- 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.
- Activity:
- To introduce while(true) loops, have students consider what will happen if you write:
while(1<2)
- 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.
- Replace
while(1<2)
withwhile(true == true)
. - Remind them that the "== true" part is implied in all conditionals and loops.
- Finally, replace
while(true == true)
towhile(true)
.