Skip to main content
Ask students "do you know in advance how many times you'll need to go through the loop?" when deciding between using a for or a while loop, because this is a good rule of thumb for them to use.
- This question is a good is a great tool for choosing between for and while loops.
- Give several small examples of looping problems, and ask the class which loop structure is appropriate, without writing any code. Once you reach a consensus, go back and explicitly write the code in the language you are using.