批次:转到在这个时候意外的错误 [英] Batch: goto was unexpected at this time error

查看:144
本文介绍了批次:转到在这个时候意外的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样的IM使学校的一个项目,我想转到菜单,如果用户输入的是无效的结果
我的code是这样的:

 :菜单
回声。
回声。
重复一下,你首先想知道吗?
回声。
回声。
回音1)工资
回音2)他们会怎么做?
附近呼应我,提供游戏设计方案3)学校
回声4)要求
回音5)现金
回声。
回声。
集/ p =选择输入号码:
如果选用%==%1页转到工资
如果选用%==%2转到做
如果选用%==%3转到学校
如果选用%==%4转到REQ
如果选用%==%5转到学分
转到菜单

当我输入的输入,还有那闪烁结果行
后藤是意外,此时然后退出结果
我究竟做错了什么?结果
我要补充一点,我的输入不是一个有效的选项。 (1,2,3,4,5)


解决方案

 如果选择%==%1页转到工资

想象一下,这是什么会做,当%选择%是空的。然后,线可能会被解读为:

 如果== 1页转到工资

显然,一个语法错误。 转到出人意料。

要避免这种情况,用

 如果选择%%= =1转到工资

这将被解读为:

 如果==1转到工资

语法现在是确定的。

So im making a project for school and i want to goto menu if the user input is not valid
My code is this:

:menu  
echo.  
echo.  
echo What would you like to know first?
echo.
echo.
echo 1) Salary
echo 2) What Do they do?
echo 3) Schools near me that offer game design programs
echo 4) Requirements
echo 5) Credits
echo.
echo.
set /p choice="Enter Number: "
if %choice% == 1 goto salary
if %choice% == 2 goto do
if %choice% == 3 goto schools
if %choice% == 4 goto req
if %choice% == 5 goto credits
goto menu

when i enter input, there is a line that flashes
Goto was unexpected at this time then exits
What am i doing wrong?
I should add that my input is not a valid option. (1,2,3,4,5)

解决方案

if %choice% == 1 goto salary

Imagine, what this would do, when %choice% is empty. The line would then be read as:

if  == 1 goto salary

Obviously a syntax error. "goto was unexpected".

To avoid this, use

if "%choice%" == "1" goto salary

This would be read as:

if "" == "1" goto salary

Syntax is ok now.

这篇关于批次:转到在这个时候意外的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆