The code is always in a larger context:
- some code happens before we get to the check
- then we have the code that might or might not get executed, depending on the condition being checked
- then we have more code that happens regardless
For example:
gui.showAquarium(); // always display aquarium // Move once (turn if necessary) if ( fish.atWall() == true ) // check whether fish is at the wall { fish.changeDir(); // turn around (but only if at wall) } fish.moveForward(); // always move forward (not part of condition) gui.showAquarium(); // always display aquarium // Move again (turn if necessary) if ( fish.atWall() == true ) // check whether fish is at the wall { fish.changeDir(); // turn around (but only if at wall) } fish.moveForward(); // always move forward (not part of condition) gui.showAquarium(); // always display aquarium
Needs to Turn | After Turn & Move | After Another Move |
---|---|---|
![]() |
![]() |
![]() |