View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Loops/Iteration - Teaching Tips

Start with asking someone to do something for a set number of times (like clap your hands 12 times). Ask everyone if they did it right. How did they know? Point out that they had to have counted and incremented the count each time and stopped when the count reached the desired value.

Show a while loop. It is easier to understand than a for loop. Point out the need for a variable to hold the count and that it should be declared outside the loop (so you don't keep making new variables each time). Point out the need to continue the loop until the desired count was reached. Point out the need to stop the loop when the count is the desired value. Point out the need to increment the count at the end of the body of the loop.

When you move to for loops point out that the same thing happens as in the while loop but it is a short-hand to make it simpler for programmers to not forget to initialize the counter and increment it.

Link to this Page