Here’s a loop in Scratch:
This is the syntax for a for loop:
for (var i = 0; i < 5; i++)
Each part of the for loop is executed at a specific time. The first part is supposed to initialize your loop and gets run at the beginning of the loop. The second part is run at the beginning of each time through the loop and exits the loop if the condition given is false. The last part of the loop runs at the end of the loop and modifies your loop variable to the next number.
In this case, the loop variable i will start at 0, run through the loop, then go to 1, run through the loop, and so on until it hits 5. When it goes to 5, it doesn’t run through the loop.
Again, resources for week 3:
- Crunchzilla’s Code Monster lesson loops (lessons 12-14):http://www.crunchzilla.com/code-monster
- Khan Academy’s lesson on looping:https://www.khanacademy.org/computing/computer-programming/programming/looping
- Code Academy’s for loop and while loop lesson:
And assignment for week 3: http://jsfiddle.net/zeroth_hour/nw1um6gn/