Loop Basics
Reading
- Read this code. (Remember to run the code for yourself, see what it does, and try experimenting with it. Here are the instructions.)
Important concepts
- for-each loop
- while loop
- C-style for loop
- break, continue
- infinite loop
- off-by-one error
Things to consider (exercises for yourself, not to turn in)
- What is the purpose of each of the three expressions that appear in the control line of a C-style for loop?
-
The reading mentions three common looping patters that we use in programming:
Pattern name Java idiom Java syntax repeat until sentinel while loop while(___) { ... }do n times C-style for loop for(___; ___; ___) { ... }for each element for-each loop for(___ : ___) { ... }In what situations would you want to use each one of these?
Your response
What was particularly interesting, confusing, or exciting to you in this reading?