
-----------------------------------
batman
Wed Mar 01, 2006 4:14 pm

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:


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.

   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:


 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.


 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.

-----------------------------------
Booya
Wed Mar 01, 2006 4:40 pm

Tutorial on For Loops
-----------------------------------
Nice tutorial on for loops. I understand it a lot now. Thanks!

-----------------------------------
jamonathin
Wed Mar 01, 2006 4:42 pm


-----------------------------------
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,  [url=http://www.compsci.ca/v2/viewtopic.php?t=3678]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
Wed Mar 01, 2006 8:13 pm


-----------------------------------
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 [url=http://www.compsci.ca/v2/viewtopic.php?t=9619]Improving Tutorials topic would be the ideal place to get information on what tutorials need to be made. ;)

-----------------------------------
jamonathin
Wed Mar 01, 2006 11:10 pm


-----------------------------------
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 

blah blah blah w/e  :P
