Mai*_*are 3 comparison numbers batch-file inequalities
我在批处理代码中遇到 <、> 和 == 等数字比较的困难。我正在做的是生成一个随机数并使用该答案来做某事,这就是我所写的:
set rand=%random%
set rand=%rand:~1,1%
If %rand%==9 goto nine
If %rand%>5 goto above 5
If %rand%>1 goto above 1
If %rand%==0 goto zero
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,代码就会关闭。我尝试在被比较的两个对象和不等式之间放置空间,但它仍然不起作用。
请记住,这是 Windows 上的批处理代码。
for if 命令使用这些键而不是等于和大于符号;
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal
Run Code Online (Sandbox Code Playgroud)
对于 Equ tho,我建议使用 == 而不是 equ。更容易打字。
阅读 HELP IF然后尝试这个
if %rand% equ 9 goto nine
if %rand% gtr 5 goto above5
goto below5
Run Code Online (Sandbox Code Playgroud)
注意标签名称不能包含空格
作为额外的奖励,请阅读HELP SET并将您尝试获取随机 0 到 9 数字的方式更改为
set /a rand=%random% %% 10
Run Code Online (Sandbox Code Playgroud)