Conditional Statements


The code is always in a larger context:

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 TurnAfter Turn & Move After Another Move

Alyce Brady, Kalamazoo College