Help with the "gtr" "lss" etc arguments in the "if" command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Help with the "gtr" "lss" etc arguments in the "if" command

#1 Post by Rileyh » 12 Sep 2011 22:13

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

Bob D
Posts: 20
Joined: 07 Sep 2011 18:32
Location: Eastern Australia

Re: Help with the "gtr" "lss" etc arguments in the "if" comm

#2 Post by Bob D » 13 Sep 2011 16:54

have you looked at IF /? :?:

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: Help with the "gtr" "lss" etc arguments in the "if" comm

#3 Post by Rileyh » 13 Sep 2011 20:44

@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

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Help with the "gtr" "lss" etc arguments in the "if" comm

#4 Post by trebor68 » 14 Sep 2011 02:43

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 abc

Robert

Exouxas
Posts: 34
Joined: 01 Sep 2011 12:52

Re: Help with the "gtr" "lss" etc arguments in the "if" comm

#5 Post by Exouxas » 14 Sep 2011 02:57

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

Post Reply