Difference between revisions of "Loops"

From CodeStuff
Jump to: navigation, search
(Created page with "This is a very simple loop. <edcode> for (var i=0; i<10; i+=1) { print("the value of i is currently "+i); } </edcode> This is called a for loop and is most often used...")
(No difference)

Revision as of 02:06, 19 June 2014

This is a very simple loop.


This is called a for loop and is most often used for counting a number of times to run a piece of code.

for Loops

for loops take the form

for(where_to_start; how_long_to_run; what_to_change) {  }
Where to start When to End What to Change
Code var i=0 i<10 i+=1
What it does Creates a variable called i

sets i to zero

keep running the loop until

i<10 is no longer true

increase the value of i by 1


while Loops

The for loop can be thought of as a simplified form of the while loop.

do while loops

do while loops enable you to move the check to after the loop contents have been run, instead of before.