Listing 2. Source code for program named Alice0170b.

Alice0170b's Code

Created by: Dick Baldwin

world

Events

When the world starts
Do:
world.main ( );


Methods

  public void main ( ) {
    Boolean testResult = true ; Number userInputValue = 1 ;
       // Copyright 2007, R.G.Baldwin
  doInOrder {
       // Illustrates use of relational and logical operators.
  // This is a different formulation of the solution to
  // the same problem as in the program named Alice0170a.
  // This alternate solution is based on deMorgan's theorem.
  // Program loops for as long as user keeps entering
  // integers outside the range of 1 to 3 inclusive.
  }
  // Perform a priming read and compute test result.
  doInOrder {
       userInputValue .set( value , ( NumberDialog( question = Enter an integer between 1 and 3 inclusive. ) ) ); duration = 0 seconds
  testResult .set( value , ( ! ( ( ( ! ( userInputValue < 1 ) ) && ( ! ( userInputValue > 3 ) ) ) ) ) ); duration = 0 seconds
  }
  // Execute a "while" loop.
  while ( testResult ) {
       // Execute this code when testResult is true.
  penguin .say( Out of range. Try again. ); duration = 2 seconds
  // Get new input and update value of testResult.
  doInOrder {
       userInputValue .set( value , ( NumberDialog( question = Enter an integer between 1 and 3 inclusive. ) ) ); duration = 0 seconds
  testResult .set( value , ( ! ( ( ( ! ( userInputValue < 1 ) ) && ( ! ( userInputValue > 3 ) ) ) ) ) ); duration = 0 seconds
  }
  }
  // Execute this code when testResult is false.
  doTogether {
       // Penguin speaks, turns, and walks away.
  penguin .say( Thanks, I'm outa here. ); duration = 20 seconds
  penguin .turn( RIGHT , .375 revolutions );
  penguin.walking ( x = 100 );
  }
  }