Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number Comparisons in Batch Code

I'm having difficulty with number comparisons like <, >, and == in my Batch code. What Im doing is generating a random number and using that answer to do something, this is what I've written:

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

And the code just closes when I run it. I tried putting space between the two objects being compared and the inequality but it still doesn't work.

Remember, this is Batch code on Windows.

like image 802
Maikeru Konare Avatar asked Oct 19 '25 15:10

Maikeru Konare


1 Answers

For the if commands use these keys instead of the equal and greater than symbols:

EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal

But I would suggest using == instead of EQU. It is easier to type.

like image 143
EDG Avatar answered Oct 21 '25 13:10

EDG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!