set /a num=1
:top
set /a num=%num%+1
echo %num%
goto top
program untuk menambah terus dan terus sampai ctrl+c
So now that we can use variables what if we have a choice of options, like:
press 1 to say Hello.
press 2 to say Goodbye.
We use the "IF" command, for example:
Type this in your CMD:
if 1==1 echo See it works!
(==) means "is equal to", you could also type "EQU")
We got a message saying "See it works!"
Now type this:
if 1==2 echo It Works!
We didn't see anything because 1 does not equal 2
If we want to wait for the user to put something in we add a /p and leave the part after the variable empty.
Like this:
set /p variablename=
That means that the computer will wait for you to put in something.
so we type:
**************************************
@echo off
set v1=hi!!
set v2=bye!!
echo Press 1 to say HI!
echo Press 2 to say BYE!
set /p you=
if %you%==1 echo %v1%
if %you%==2 echo %v2%
pause
**************************************
This is telling the computer that if we type 1, it must echo HI!, and if we say 2 it must echo BYE!!
and if not 1 or 2, computer just end work
No comments:
Post a Comment