The Do Statement

The 'do-while' loop is a variation of the while loop. 'do-while' loops always execute at least once, whereas while loops may never execute.

8. Boolean Expression in a Condition


The test part of the loop can use the OR operator to allow several choices.

Boolean Expression in a Condition

The test part of a loop (any of the three varieties) is a boolean expression. We want a boolean expression that evaluates to true if the user enters:

      • yes
      • YES
      • Y
      • y

and evaluates to false for anything else. Here is a near-complete expression:

while ( chars.equals( "yes" )   chars.equals( "YES" )   
        chars.equals( "y" )     chars.equals( "Y" )  )

Question 8:

Fill in the blanks.