Operator 'greater than' and 'less than' in batch

2

Friends, I have the following script, which I developed as a simple exercise, but I do not work correctly with the logical operators < and > that I understand in Batch are LSS and GTR .

Here my code:

@echo off

title Edad

:main
cls
echo.
echo Introduce tu edad
echo.
set /p edad=

:eleccion
if %edad%==(0-12) (goto:niño) else(
    if %edad% LSS 18 (goto:adolecente) else(
        if %edad% LSS 45 (goto:adulto) else(
            if %edad% GTR 44 (goto:anciano) else(goto:error)
            )
        )
    )


:error
cls
echo.
msg * Error en valor de tu edad, por favor introduzca un número valido.
echo.
goto:main


:niño
echo Eres un niño
pause
exit

:adolecente
echo Eres un adolecente
pause
exit

:adulto
echo Eres un adulto
pause
exit

:anciano
echo Eres un anciano
pause
exit
    
asked by Juan Carlos Terán 21.11.2017 в 02:27
source

1 answer

6

Operators for BAT (Windows)

  • EQU , which is the equivalent of ==
  • NEQ , Used to verify that it is not the same.
  • LSS , To check if the number is smaller
  • LEQ , To verify if it is less than or equal.
  • GTR , If greater
  • GEQ , If it is greater and equal.

The code would be better to put it like this:

if %edad% LEQ 0 goto:error
if %edad% LEQ 12 goto:chico
if %edad% LEQ 18 goto:adolecente
if %edad% LSS 45 goto:adulto
goto:anciano

The BAT is sequential ... simply if it is fulfilled it jumps (goto) ... and you do not need the ELSE !!

    
answered by 21.11.2017 / 02:42
source