Thinking logically means working out, before any code is written, where a solution has to choose between alternatives and what each choice depends on.
Finding the Decision Points
• Wherever the description says if, otherwise, unless, depending on, until or while
• Wherever an input has to be validated before it is used
• Wherever a loop has to decide whether to repeat or to stop
• Wherever the user chooses between options, such as a menu
A player rolls a dice, moves that many squares and follows any instruction on the square. The first player to reach square 100 wins, and the game is a draw if a 30-minute timer runs out.
| Decision point | Condition tested | If true | If false |
|---|---|---|---|
| After moving | Does the square have an instruction? | Move the number of places it says | Stay on the square |
| After any extra move | Is the player on square 100? | Announce the player as the winner | Carry on with the game |
| After each turn | Has the timer reached 0? | Announce a draw | Pass the turn to the next player |