Skip to main content
Lesson 8 - Structured Programming, Control Structures, if-else Statements, Pseudocode
Lesson MenuPreviousNext
  
Boolean Identifiers page 13 of 15

  1. The execution of if-else statements depends on the value of the Boolean expression. We can use boolean variables to write code that is easier to read.

  2. For example, the boolean variable done could be used to write code that is more English-like.

    Instead of

    if (done == true)  
      System.out.println("We are done!");

    we can write

    if (done) 
      System.out.println("We are done!");
  3. Using Boolean identifiers with conditional loops allows a separation of solving expressions from thinking about program control. Here is an example solution using the while control structure (to be covered in the next lesson), presented in a blend of Java and pseudocode:

    boolean done = false;
    
    while (!done)
      // do some code that could change the value of done
  4. Where appropriate you are encouraged to use boolean variables to aid in program flow and readability.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.