Posted: Wed Mar 01, 2006 4:14 pm Post subject: Quick Tutorial on For Loops
Heres a quick tutorial on for loops.
A for loop is much different then a regular loop. A regular loop repeats a section of a program till it is exited or stopped using the exit statement.
Example:
code:
loop
put "Hello World"
end loop
This will repeat the words "Hello World" till exited by the user.
A for loop is different. Heres a basic example of one.
code:
for i : 1 .. 10
put i
end for
This program outputs the numbers 1 to 10 down the screen. What's with the "i" you might ask? The "i" is a variable of course. when you right a for statement you are allowed to declare a variable but that variable can only be used inside a for statement. If you try to use it outside the for statement then there will be an error.
Ok so now you know the basic of a for loop. Using this knowledge you can do all sorts of things using the for loop. Do count backwards, just place the word decreasing after the for.
Example:
code:
for decreasing j : 10 .. 1
put j
end for
This code will count down from 10 to 1. You can also do something like this.
code:
for decreasing j : 10 .. 1 by 2
put j
end for
Place the word "by" after the numbers, in this case there 10 and 1 and choose a value to count down from. This code above will count down from 10 to 1 by 2.
That was my quick tutorial on for loops. If you have any questions of for loops just email me and i'll be glad to answer them.
Sponsor Sponsor
Booya
Posted: Wed Mar 01, 2006 4:40 pm Post subject: Tutorial on For Loops
Nice tutorial on for loops. I understand it a lot now. Thanks!
jamonathin
Posted: Wed Mar 01, 2006 4:42 pm Post subject: (No subject)
That's a nice lil quickie tutorial on for loops. Not to knock on your tutorial, or discourage you from sharing your knowledge, but this tutorial was already made, click! Next time, just take a gander through that "Turing Walkthrough" link, it's a sticky in the Tutorial section, and just see what tutorials haven't been done, or if you see any that can use some work.
Cervantes
Posted: Wed Mar 01, 2006 8:13 pm Post subject: (No subject)
jamonathin wrote:
Next time, just take a gander through that "Turing Walkthrough" link, it's a sticky in the Tutorial section, and just see what tutorials haven't been done, or if you see any that can use some work.
Actually, the Improving Tutorials topic would be the ideal place to get information on what tutorials need to be made.
jamonathin
Posted: Wed Mar 01, 2006 11:10 pm Post subject: (No subject)
Cervantes wrote:
jamonathin wrote:
Next time, just take a gander through that "Turing Walkthrough" link, it's a sticky in the Tutorial section, and just see what tutorials haven't been done, or if you see any that can use some work.
Actually, the Improving Tutorials topic would be the ideal place to get information on what tutorials need to be made.