Loops 我有一个错误,说明我有一个没有do的循环

Loops 我有一个错误,说明我有一个没有do的循环,loops,vbscript,Loops,Vbscript,也许我没有看到,但我真的相信我有一个永远的循环!有人能帮忙吗?我从一个初始do开始,这样我就可以给用户再次使用代码的能力。谢谢你们的帮助 代码: 道格拉斯·豪写的《代码》 选项显式 暗淡的彩色Picone、彩色Pictwo、tryAgain “开始做什么 做 “第一个提示 做 Wscript.StdOut.WriteLine“选择原色(即蓝色、红色或黄色):” colorPicOne=lcase(wscript.StdIn.ReadLine) 如果颜色为“蓝色”,颜色为“红色”,颜色为“黄色”,

也许我没有看到,但我真的相信我有一个永远的循环!有人能帮忙吗?我从一个初始do开始,这样我就可以给用户再次使用代码的能力。谢谢你们的帮助

代码:

道格拉斯·豪写的《代码》 选项显式 暗淡的彩色Picone、彩色Pictwo、tryAgain “开始做什么 做 “第一个提示 做 Wscript.StdOut.WriteLine“选择原色(即蓝色、红色或黄色):” colorPicOne=lcase(wscript.StdIn.ReadLine) 如果颜色为“蓝色”,颜色为“红色”,颜色为“黄色”,则 Wscript.StdOut.WriteLine“不是原色!请选择其他颜色:” 其他的 退出do 如果结束 当颜色为“蓝色”或“红色”或“黄色”时循环 “第二次提示 做 Wscript.StdOut.WriteLine“选择另一种原色(即蓝色、红色或黄色):” colorPicTwo=lcase(wscript.StdIn.ReadLine) 如果colorPicTwo为“蓝色”,colorPicTwo为“红色”,colorPicTwo为“黄色”,则 Wscript.StdOut.WriteLine“不是原色!请选择其他颜色:” 其他的 退出do 如果结束 当colorPicTwo“蓝色”或colorPicTwo“红色”或colorPicTwo“黄色”时循环 如果colorPicOne=“红色”和colorPicTwo=“蓝色”,则 Wscript.StdOut.Writeline“您的颜色是紫色的!” 其他的 如果colorPicOne=“蓝色”和colorPicTwo=“红色”,则 Wscript.StdOut.Writeline“您的颜色是紫色的!” 如果结束 如果colorPicOne=“红色”和colorPicTwo=“黄色”,则 Wscript.StdOut.Writeline“您的颜色是橙色!” 其他的 如果colorPicOne=“黄色”和colorPicTwo=“红色”,则 Wscript.StdOut.Writeline“您的颜色是橙色!” 如果结束 如果colorPicOne=“蓝色”和colorPicTwo=“黄色”,则 Wscript.StdOut.Writeline“您的颜色是绿色的!” 其他的 如果colorPicOne=“黄色”和colorPicTwo=“蓝色”,则 Wscript.StdOut.Writeline“您的颜色是绿色的!” 如果结束 Wscript.Stdout.WriteLine“是否重试?(是或否):” tryAgain=lcase(Wscript.StdIn.ReadLine) 如果tryAgain=“否”,则 Wscript.Stdout.WriteLine“祝您有愉快的一天” 退出do 如果tryAgain=“是”,则 Wscript.Stdout.WriteLine“好的!” 其他的 Wscript.Stdout.WriteLine“抱歉,您的响应无效。再见!” 退出do 如果结束 如果结束 在tryAgain=“是”时循环
我的错误表明我有一个
循环
,而没有
do

错误消息具有误导性。问题不在于有一个
循环
而没有
Do
,而是
循环
在同一上下文中没有前面的
Do

这就是您观察到的行为的实际原因:

if colorPicOne = "red" and colorPicTwo = "blue" then
  Wscript.StdOut.Writeline "Your color is purple!"
else
  if colorPicOne = "blue" and colorPicTwo ="red" then
    Wscript.StdOut.Writeline "Your color is purple!"
end if
从缩进判断,你的意思可能是:

if colorPicOne = "red" and colorPicTwo = "blue" then
  Wscript.StdOut.Writeline "Your color is purple!"
else
  if colorPicOne = "blue" and colorPicTwo ="red" then Wscript.StdOut.Writeline "Your color is purple!"
end if
但你实际拥有的(适当的缩进)是:

或者像这样:

If condition Then statement Else other_statement
If condition Then
  statement
Else
  other_statement
End If
i、 e.如果将
语句
放在新行上,则必须使用
结束if
关闭整个表达式。此规则的唯一例外是使用换行符(
\uu
)换行:


如果没有
End If
,上面的内容是有效的,因为从技术上讲,它只是一行。

问题不在于你有一个没有do的循环,而在于你有几个(我发现3个)block
If
语句没有用
End If
正确关闭。在嵌套的结果级别,最终的
循环
没有
do
。我认为这就是你的意图:

'Written by Douglas Howe
Option Explicit
Dim colorPicOne, colorPicTwo, tryAgain

'initial do
do
    'first prompt
    do
        Wscript.StdOut.WriteLine "Pick a primary color (i.e blue, red, or yellow): "
        colorPicOne = lcase(wscript.StdIn.ReadLine)
        if colorPicOne <> "blue" and colorPicOne <> "red" and colorPicOne <> "yellow" then
            Wscript.StdOut.WriteLine "Not a primary color! Please pick another color: "
        else 
            exit do
        end if
    loop while colorPicOne <> "blue" OR colorPicOne <> "red" or colorPicOne <> "yellow"

    'second prompt
    do
        Wscript.StdOut.WriteLine "Pick another primary color (i.e blue, red, or yellow): "
        colorPicTwo = lcase(wscript.StdIn.ReadLine)
        if colorPicTwo <> "blue" and colorPicTwo <> "red" and colorPicTwo <> "yellow" then
            Wscript.StdOut.WriteLine "Not a primary color! Please pick another color: "
        else
            exit do
        end if
    loop while colorPicTwo <> "blue" OR colorPicTwo <> "red" or colorPicTwo <> "yellow"

    if colorPicOne = "red" and colorPicTwo = "blue" then
        Wscript.StdOut.Writeline "Your color is purple!"
    else
        if colorPicOne = "blue" and colorPicTwo ="red" then
            Wscript.StdOut.Writeline "Your color is purple!"
        end if 'This was missing
    end if

    if colorPicOne = "red" and colorPicTwo = "yellow" then
        Wscript.StdOut.Writeline "Your color is orange!"
    else
        if colorPicOne = "yellow" and colorPicTwo ="red" then
            Wscript.StdOut.Writeline "Your color is orange!"
        end if

        if colorPicOne = "blue" and colorPicTwo = "yellow" then
            Wscript.StdOut.Writeline "Your color is green!"
        else
            if colorPicOne = "yellow" and colorPicTwo ="blue" then
                Wscript.StdOut.Writeline "Your color is green!"
            end if 'This was missing
        end if

        Wscript.Stdout.WriteLine "Would you like to try again? (yes or no) :"
        tryAgain =lcase(Wscript.StdIn.ReadLine)

        if tryAgain = "no" then
            Wscript.Stdout.WriteLine "Have a nice day"
            exit do
            if tryAgain = "yes" then
                Wscript.Stdout.WriteLine "Ok!"
            else 
                Wscript.Stdout.WriteLine "Sorry, you gave an invalid response. Good Bye!"
                exit do
            end if 'This was missing
        end if
    end if
loop while tryAgain = "yes"
道格拉斯·豪写的《代码》 选项显式 暗淡的彩色Picone、彩色Pictwo、tryAgain “开始做什么 做 “第一个提示 做 Wscript.StdOut.WriteLine“选择原色(即蓝色、红色或黄色):” colorPicOne=lcase(wscript.StdIn.ReadLine) 如果颜色为“蓝色”,颜色为“红色”,颜色为“黄色”,则 Wscript.StdOut.WriteLine“不是原色!请选择其他颜色:” 其他的 退出do 如果结束 当颜色为“蓝色”或“红色”或“黄色”时循环 “第二次提示 做 Wscript.StdOut.WriteLine“选择另一种原色(即蓝色、红色或黄色):” colorPicTwo=lcase(wscript.StdIn.ReadLine) 如果colorPicTwo为“蓝色”,colorPicTwo为“红色”,colorPicTwo为“黄色”,则 Wscript.StdOut.WriteLine“不是原色!请选择其他颜色:” 其他的 退出do 如果结束 当colorPicTwo“蓝色”或colorPicTwo“红色”或colorPicTwo“黄色”时循环 如果colorPicOne=“红色”和colorPicTwo=“蓝色”,则 Wscript.StdOut.Writeline“您的颜色是紫色的!” 其他的 如果colorPicOne=“蓝色”和colorPicTwo=“红色”,则 Wscript.StdOut.Writeline“您的颜色是紫色的!” 如果“缺少此项”,则结束 如果结束 如果colorPicOne=“红色”和colorPicTwo=“黄色”,则 Wscript.StdOut.Writeline“您的颜色是橙色!” 其他的 如果colorPicOne=“黄色”和colorPicTwo=“红色”,则 Wscript.StdOut.Writeline“您的颜色是橙色!” 如果结束 如果colorPicOne=“蓝色”和colorPicTwo=“黄色”,则 Wscript.StdOut.Writeline“您的颜色是绿色的!” 其他的 如果colorPicOne=“黄色”和colorPicTwo=“蓝色”,则 Wscript.StdOut.Writeline“您的颜色是绿色的!” 如果“缺少此项”,则结束 如果结束 Wscript.Stdout.WriteLine“是否重试?(是或否):” tryAgain=lcase(Wscript.StdIn.ReadLine) 如果tryAgain=“否”,则 Wscript.Stdout.WriteLine“祝您有愉快的一天” 退出do 如果tryAgain=“是”,则 Wscript.Stdout.WriteLine“好的!” 其他的 Wscript.Stdout.WriteLine“抱歉,您的响应无效。再见!” 退出do 如果“缺少此项”,则结束 如果结束
If condition Then
  statement
Else
  other_statement
End If
If condition Then _
  statement
'Written by Douglas Howe
Option Explicit
Dim colorPicOne, colorPicTwo, tryAgain

'initial do
do
    'first prompt
    do
        Wscript.StdOut.WriteLine "Pick a primary color (i.e blue, red, or yellow): "
        colorPicOne = lcase(wscript.StdIn.ReadLine)
        if colorPicOne <> "blue" and colorPicOne <> "red" and colorPicOne <> "yellow" then
            Wscript.StdOut.WriteLine "Not a primary color! Please pick another color: "
        else 
            exit do
        end if
    loop while colorPicOne <> "blue" OR colorPicOne <> "red" or colorPicOne <> "yellow"

    'second prompt
    do
        Wscript.StdOut.WriteLine "Pick another primary color (i.e blue, red, or yellow): "
        colorPicTwo = lcase(wscript.StdIn.ReadLine)
        if colorPicTwo <> "blue" and colorPicTwo <> "red" and colorPicTwo <> "yellow" then
            Wscript.StdOut.WriteLine "Not a primary color! Please pick another color: "
        else
            exit do
        end if
    loop while colorPicTwo <> "blue" OR colorPicTwo <> "red" or colorPicTwo <> "yellow"

    if colorPicOne = "red" and colorPicTwo = "blue" then
        Wscript.StdOut.Writeline "Your color is purple!"
    else
        if colorPicOne = "blue" and colorPicTwo ="red" then
            Wscript.StdOut.Writeline "Your color is purple!"
        end if 'This was missing
    end if

    if colorPicOne = "red" and colorPicTwo = "yellow" then
        Wscript.StdOut.Writeline "Your color is orange!"
    else
        if colorPicOne = "yellow" and colorPicTwo ="red" then
            Wscript.StdOut.Writeline "Your color is orange!"
        end if

        if colorPicOne = "blue" and colorPicTwo = "yellow" then
            Wscript.StdOut.Writeline "Your color is green!"
        else
            if colorPicOne = "yellow" and colorPicTwo ="blue" then
                Wscript.StdOut.Writeline "Your color is green!"
            end if 'This was missing
        end if

        Wscript.Stdout.WriteLine "Would you like to try again? (yes or no) :"
        tryAgain =lcase(Wscript.StdIn.ReadLine)

        if tryAgain = "no" then
            Wscript.Stdout.WriteLine "Have a nice day"
            exit do
            if tryAgain = "yes" then
                Wscript.Stdout.WriteLine "Ok!"
            else 
                Wscript.Stdout.WriteLine "Sorry, you gave an invalid response. Good Bye!"
                exit do
            end if 'This was missing
        end if
    end if
loop while tryAgain = "yes"