Asked by Gurpreet Verka on Jun 18, 2024
Verified
boolean found = false;
Int num;
Int square;while (!found)
{
Num = console.nextInt() ;
Square = num * num;
If (square > 40)
Found = true;
}The above code is an example of a(n) ____ loop.
A) flag-controlled
B) counter-controlled
C) EOF-controlled
D) sentinel-controlled
Flag-controlled
A loop or program segment that uses a boolean variable (flag) to control its execution flow.
While Loop
A programming construct that executes a block of code repeatedly as long as a specified condition evaluates to true.
- Gain insight into the mechanisms of counter-controlled, sentinel-controlled, and flag-controlled loops.
Verified Answer
JD
Juanita DevanJun 22, 2024
Final Answer :
A
Explanation :
This is a flag-controlled loop because the "found" boolean variable is being used as a flag to determine when to exit the loop.
Learning Objectives
- Gain insight into the mechanisms of counter-controlled, sentinel-controlled, and flag-controlled loops.