@echo off
title Variables
set age= default
set name = defualt
set teaornah = deafault
set transport = deafault
echo How old are you, my fine friend?
set /p age=
echo So, you are %age% years old? Interesting!
pause
echo And what might your namesake be, old fellow?
set /p name=
echo Oh that's right! It's %name%! I'm am absolutly HORRID with names! Dear me!
pause
echo so, %name%, would you like to go to get some tea?
set /p teaornah=
if %teaornah% == yes goto yes
if %teaornah% == no goto no
:yes
echo very well then!
echo Would you like to take a bus or car?
set /p transport=
if transport == car goto car
if transport == bus goto bus
:car
echo we seem to be caught up in a traffic jam.
echo how awful.
echo fine weather, huh?
echo you're not very talkative.
echo goodbye.
pause
exit
:bus
echo You are victorious, %name%!
pause
exit
:no
echo Oh. How bad. I think I shall kill you now.
pause
exit
这是我的代码。我是一个初学者批处理用户,并且刚刚学习了goto命令,但是当在set / p transport =之后键入“bus”时,它不会转到:总线它转到:car。我想要一些帮助,因为我发现了其他程序的类似问题。转到:没有作用,如同转到:是的,但没有其他转到的作品。请帮忙!
答案 0 :(得分:2)
这两组线之间有什么区别?
if %teaornah% == yes goto yes
if %teaornah% == no goto no
if transport == car goto car
if transport == bus goto bus
实际上,最后两行都没有。您的代码会检查单词transport
是否等于单词car
并确定单词transport
是否正确,因此它会继续到下一行。然后检查单词bus
是否等于单词car
并确定单词SET
是否正确,因此它会继续到下一行,即SET FLAG = N
标签的开头。
关于您的代码的其他一些想法:
批处理对set "var=value"
语句中的空格敏感。 var
将名为“FLAG Space ”的变量设置为值“ Space N”
if /i "%var%"=="value"
语法可确保批处理行上的任何尾随空格不包含在分配给{{1}}的值中。
{{1}}对包含分隔符的变量/值进行比较(例如空格)'/ i'使比较不区分大小写。