Categories
Scripts Windows Batch

Relational Operators

04Operators_Relational.bat

::this program will demonstrate relational operators. Following list of relational operators are supported
::EQU is for EQUAL TO
::NEQ is for Not Equal TO
::LSS is for Less Than
::LEQ is for Less Than Or Equal To
::GTR is for Greater Than
::GEQ is for Greater Or Than Equal To

@echo off

set /A var_1=10
set /A var_2=20

if %var_1% EQU %var_2% echo "var_1 and var_2 are equal"
if %var_1% NEQ %var_2% echo "var_1 and var_2 are not equal"
if %var_1% LSS %var_2% echo "var_1 is less than var_2"
if %var_1% LEQ 10 echo "var_1 is less than or equal to 10"
if %var_2% GTR %var_1% echo "var_2 is greater than var_1"
if %var_2% GEQ 20 echo "var_2 is greater than or equal to 20"

pause

Output

Leave a comment

Design a site like this with WordPress.com
Get started