Music Banter - View Single Post - Batch Programming
View Single Post
Old 08-27-2009, 01:47 PM   #3 (permalink)
Guybrush
Juicious Maximus III
 
Guybrush's Avatar
 
Join Date: Nov 2008
Location: Scabb Island
Posts: 6,525
Default

The only "real" programming I've done besides this is php which is rather useful I find. Batch is just for fun of course. A funny thing about batch is the way you can divide your code into different sections and then jump to the different ones using the goto command. You can also use that in order to create for-oops ..

Code:
:start
@echo off
set /a var="1"
echo.

:loop
echo %var%
set /a var=%var%+1
if "%var%"=="101" goto end
goto loop

:end
set var=
This script would list numbers from 1 to 100, each on a separate line (set defines a variable - /a that it's a numerical value, echo outputs something to screen, goto jumps to different sections in the script and if runs a command when the if-criteria is met).

In the above example, there's an if-argument that when fulfilled jumps to the end of the script .. But if it's criteria is not met, the "goto loop" command will run instead, making the program run through the loop section one more time. I think it's a quite charming and intuitive way of doing it
__________________
Something Completely Different
Guybrush is offline   Reply With Quote