You are here

Two Flags with the Same Meaning

6 February, 2015 - 17:27

Sometimes we will use an iteration control structure of do while to allow us to decide if we want to do the loop action again. A variable might be named "loop response" with the user prompted for their answer of 'y' for yes or 'n' for no. Once the answer is retrieved from the keyboard and stored in our flag variable of "loop response" the test expression to control the loop might be:

Example 13.5: simple flag comparison

loop_response equals 'y' 

This is fne but what if the user accidentally has on the caps lock. Then his response of 'Y' would not have the control structure loop and perform the action again. The solution lies in looking at the flag twice. Consider:

Example 13.6: complex flag comparison

loop_response equals 'y' or loop response equals 'Y' 

We look to see if the flag is either a lower case y or an upper case Y by using a more complex Boolean expression with both relational and logical operators.