[Tutorial] [Blitz] For loops
Author |
Message |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Thu Feb 19, 2004 8:57 pm Post subject: [Tutorial] [Blitz] For loops |
|
|
For Loops
what they are
For loops are used to execute a code between the 'for' and the 'next' lines. The code is executed a set number of times, decided by the parameters you enter at the 'for' line. For loops also keep track of how many times the code has been repeated in a variable (that doesn't need to be declared beforehand)
Syntax
the first line
code: |
For qwerty = 1 To 10
|
qwerty can be anything you want, as long as it is not a command or already used variable. It is the counter. 1 To 10 sets the number that qwerty begins at, and 10 sets the number that qwerty ends at. This for loops will execute code 10 times.
The last line
Simple enough
you can put whatever code you want between there. It's totally up to you!
Here's an example of code that counts to 5!!!!!!!!!!!!!!!!!!!!!
code: |
For number = 1 To 5
Print number
Next
|
You can also count by different intervals, using Step.
code: |
For number = 1 To 5 Step 2
Print number
Next
|
"Cervantes! How do I do 'decreasing' like in good ol' turing?!"
You said it! How do you do decreasing?!
code: |
For number = 5 to 1 Step -2
Print number
Next
|
tricky huh? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jonos
![](http://jonos.f2g.net/pictures/rankca.gif)
|
Posted: Thu Feb 19, 2004 9:23 pm Post subject: (No subject) |
|
|
wow, nice tutorial, really makes me understand the syntax.
is there a need for a 'decreasing' word like in turing for a decreasing for loop, or can it just be the same just with a higher first number and lower second number. |
|
|
|
|
![](images/spacer.gif) |
shorthair
![](http://www.members.shaw.ca/rfolz/domo-kun.jpg)
|
Posted: Thu Feb 19, 2004 9:30 pm Post subject: (No subject) |
|
|
You are doing such an awsome job guys , thanks so much for hte support in here ,these tutorials rock , they are alot easier to understand , unlike mine THIS is awsome you have my seal of approval ( if it means anything to you ) ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
shorthair
![](http://www.members.shaw.ca/rfolz/domo-kun.jpg)
|
Posted: Thu Feb 19, 2004 9:31 pm Post subject: (No subject) |
|
|
Psssst , just rename it with " ( Blitz ) " at hte end , to seperate it from dark in case anyone ever does some work with it |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Fri Feb 20, 2004 4:48 pm Post subject: (No subject) |
|
|
Sweet! I have the Shorthair seal of approval! Now all I need is a pic of it in my inventory
Jonos: try the following
code: |
For i = 1 To 5
Print i
Next
For k = 5 To 1
Print k
Next
|
It doesn't give you an error, it just doesn't do it.
as for why we need decreasing for loops?
You wrote that lil program that made a boarder, then I made a better one Then I made an EVEN BETTER one!! (I know, its crazy!)
code: |
Graphics 400, 400
SetBuffer BackBuffer()
x1 = 350
y1 = 50
x2 = 50
y2 = 350
For k = 0 To 350 Step 3
x1 = x1 - 3
y1 = y1 + 3
x2 = x2 + 3
y2 = y2 - 3
Line 50, y1, 50, y1 + 3
Line x1, 50, x1 - 3, 50
Line 350, y2, 350, y2 - 3
Line x2, 350, x2 + 3, 350
Flip
Next
x1 = 0
y1 = 400
x2 = 400
y2 = 0
For k = 0 To 350 Step 3
x1 = x1 + 3
y1 = y1 - 3
x2 = x2 - 3
y2 = y2 + 3
For i = 0 To 50 Step 3
Plot x1, i
Plot i, y1
Plot x2, i + 350
Plot i + 350, y2
Next
Flip
Next
;;;;;;;;;
While Not KeyHit (1)
Wend
End
|
That would have been easier with decreasing for loops. esp the first part. instead of using x1 and y1 and x2 and y2, I could have just used the for variable. |
|
|
|
|
![](images/spacer.gif) |
jonos
![](http://jonos.f2g.net/pictures/rankca.gif)
|
Posted: Fri Feb 20, 2004 4:57 pm Post subject: (No subject) |
|
|
that is some nice stuff there!!! i will give up for now, but just wait... |
|
|
|
|
![](images/spacer.gif) |
jonos
![](http://jonos.f2g.net/pictures/rankca.gif)
|
Posted: Wed Feb 25, 2004 5:40 pm Post subject: (No subject) |
|
|
hey... i found how to do decreasing, i was looking throught the blitz tutorials and i found this, straight from the help, i didn't right it:
You can also step backwards by placing a minus (-) sign after the command with the number of steps backwards you would like to take:
For A = 10 To 0 step -2
Print A
Next
This would print: 10 8 6 4 2 0 |
|
|
|
|
![](images/spacer.gif) |
shorthair
![](http://www.members.shaw.ca/rfolz/domo-kun.jpg)
|
Posted: Wed Feb 25, 2004 8:26 pm Post subject: (No subject) |
|
|
Thats one way to do it , there is a more complex way and it allowy you to add some more cool options , its used when decreasing in hte z axis , but your very right on that decreasing loop , MAKE IT A TUTORIAL |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|