- Students can struggle to understand the keyword true as being a state.
- Scaffold students to understanding why a while(true) loop continues forever using a series of expressions that will evaluate to the keyword true.
- To introduce while(true) loops, have students consider what will happen if you write:
- You could also use another always-true conditional expression.
- The goal is for students to realize that Java is checking a conditional.
- Ask students what other boolean expressions are always true.
while(true == true).
- Remind them that the "== true" part is implied in all conditionals and loops.
- Finally, replace
while(true == true)to