Page 1 of 1
Help with the "gtr" "lss" etc arguments in the "if" command
Posted: 12 Sep 2011 22:13
by Rileyh
Hi,
Could someone give me a simple sintax overview to the various arguments involving "gtr" "lss" etc in the "if" command.
Any help would be greatly appreciated,
Rileyh
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
Posted: 13 Sep 2011 16:54
by Bob D
have you looked at IF /?
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
Posted: 13 Sep 2011 20:44
by Rileyh
@bob d
Yes I have looked at that and it is quite hard to understand.
Also it is very brief and has not much info on it
Rileyh
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
Posted: 14 Sep 2011 02:43
by trebor68
See the code and test with different numbers to understand this:
Code: Select all
@echo off
cls
echo.
echo Overview of the various comparison operations in the command IF
echo.
set /p val1= value 1:
set /p val2= value 2:
echo.
echo IF %val1% EQU %val2% (command if TRUE) ELSE command if FALSE
IF %val1% EQU %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% NEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% NEQ %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% LSS %val2% (command if TRUE) ELSE command if FALSE
IF %val1% LSS %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% LEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% LEQ %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% GTR %val2% (command if TRUE) ELSE command if FALSE
IF %val1% GTR %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% GEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% GEQ %val2% (ECHO TRUE) ELSE ECHO FALSE
If you want use the value as string use the quotation marks.
IF "%val1%" LSS "%val2%" ECHO The first word is alphabetically before the second word.IF /I "%val1%" EQU "%val2%" ECHO Lowercase and uppercase are ignored - ABC is the same as abcRobert
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
Posted: 14 Sep 2011 02:57
by Exouxas
BASIC:
Code: Select all
line1: if VARIABLE1 gtr VARIABLE2 goto 1greaterthan2
line2: if VARIABLE1 lss VARIABLE2 goto 1lessthan2
line3: if VARIABLE1 equ VARIABLE2 goto 1equal2
line4: if VARIABLE1 neq VARIABLE2 goto 1notequal2
line5: if VARIABLE1 leq VARIABLE2 goto 1lessorequal2
line6: if VARIABLE1 geq VARIABLE2 goto 1greaterorequal2
Explaination:
line1: if the first variable (VARIABLE1) is greater than the second (VARIABLE2) then skip to 1greaterthan2
line2: if the first variable (VARIABLE1) is less the second (VARIABLE2) then skip to 1lessthan2
line3: if the first variable (VARIABLE1) is equal the second (VARIABLE2) then skip to 1equal2
line4: if the first variable (VARIABLE1) is not equal the second (VARIABLE2) then skip to 1notequal2
line5: if the first variable (VARIABLE1) is less or equal the second (VARIABLE2) then skip to 1lessorequal2
line6: if the first variable (VARIABLE1) is greater or equal the second (VARIABLE2) then skip to 1greaterorequal2
Hope this helped!
-Exouxas