how can i write the following as windows batch file?
while(x>y && z<x){
// Do something
}
Thanks
how can i write the following as windows batch file?
while(x>y && z<x){
// Do something
}
Thanks
There is no real while loop in batch but you can achieve the same with GOTO statements:
SETLOCAL EnableDelayedExpansion
:LOOP
IF NOT !x! GTR !y! GOTO ENDLOOP
IF NOT !z! LSS !x! GOTO ENDLOOP
<code>
GOTO LOOP
:ENDLOOP
<more code>
First you are checking if !x! is greater than !y!. If this is the case, you go on. Then you are checking if !z! is less then !x!. If this is the case you go on to the body of the loop. If one of the conditions is broken the script jumps out of the loop and goes to the code below the :ENDLOOP mark. Otherwise it executes the body and jumps back to :LOOP.
As the values of x, y and z will change (otherwise you would have an endless loop), you need SETLOCAL EnableDelayedExpansion
and access the variables with !var!
instead of %var%
to force variable evaluation at run time instead of at parse time.