11,797 views
12 votes
12 votes
what advantage is procided by using a boolean found variable in a compound condition for a search loop

User Witcher
by
2.6k points

1 Answer

11 votes
11 votes

Answer:

- the notation while(!found) { ... } is semantically very clear

- you can initialize the found boolean as false

Step-by-step explanation:

Within the while loop you will assign the compound condition to the 'found' variable. By initializing the variable with 'false' you ensure that the values used in the compound condition are valid.

Simplified example: read user input until 'Y' is pressed:

found = false;

while(!found) {

userInput = readUserInput();

found = (userInput == 'Y');

}

User Samvel Aleqsanyan
by
2.7k points