answersLogoWhite

0

What is flag controlled while loop?

Updated: 10/31/2022
User Avatar

Wiki User

7y ago

Best Answer

A while loop evaluates a conditional expression at the start of each iteration. If the conditional expression evaluates false, execution passes to the statement that immediately follows the body of the loop. If the conditional expression evaluates true, the body of the loop executes one iteration. When the end of the loop is reached, or a continue statement is encountered within the body of the loop, control passes back to the while statement where the conditional expression is re-evaluated. If a break statement is encountered within the body of the loop, the loop terminates and control passes to the next statement. If a return statement is encountered within the body of the loop, the loop terminates and control passes to the calling function.

while (expression) {

// repeats until the expression evaluates false

}

The braces are optional when the body of the loop is a simple statement. Compound statements must be enclosed in braces.

A flag-controlled while loop has a simple conditional expression that evaluates a Boolean value:

bool x;

// ...

while (x==true) { // flag-controlled loop

// ...

}

}

The above loop can also be written without the equality operator:

while (x) { // flag-controlled loop // ...

}

Moreover, any integral type (such as int or char) will implicitly convert to a bool such that non-zero values evaluate true and zero evaluates false. As such, any integral type can be used in a flag-controlled loop.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is flag controlled while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When would you use a count controlled loop vs. a flag controlled loop?

Counter Loop:Counter loop is a loop which executes statement up to a fixed number of time.In GW FOR ... NEXT loop is used as counter loop.Controlled Loop:Controlled loop is used to extend the statements till a specific condition is satisfied. In GW WHILE ... WEND is used as controlled loop.


What is meant by entry controled loop?

An exit-controlled loop is a loop where the controlling conditional expression is evaluated at the end of each iteration, as opposed to an entry-controlled loop where the expression is evaluated at the beginning of each iteration. The upshot is that an exit-controlled loop always executes at least one complete iteration whereas an entry-controlled loop might not iterate at all: int x = 100; // entry-controlled loop while (x<50) { printf ("%d\n", x++); // won't execute at all because x<50 is false } // exit-controlled loop do { printf ("%d\n", x++); // will execute one time only } while (x<50);


What is the difference between entry and exit controlled loops - in Java?

while loop and for loop are entry controlled loops as they check looping condition at the entry point. do while loop is exit controlled loop as it checks looping condition at exit point. shreeradha@yahoo.com


Compare Do-While with While Statements?

A Do-While loop looks like this: do { loop body } while (condition); and a While loop looks like this: while (condition) { loop body } The main difference is that the loop body is always run once in the Do-While loop, then the condition is checked to see if the loop should keep running. In a While loop, the condition is checked first, and it will not run the loop body at all if the condition is false.


What is a loop type?

A Loop is a programming language construct that instructs the processor to repeat a sequence of operations a number of times until a specific condition is reached. There are different types of loops. They are: * for loop * while loop * do while loop

Related questions

When would you use a count controlled loop vs. a flag controlled loop?

Counter Loop:Counter loop is a loop which executes statement up to a fixed number of time.In GW FOR ... NEXT loop is used as counter loop.Controlled Loop:Controlled loop is used to extend the statements till a specific condition is satisfied. In GW WHILE ... WEND is used as controlled loop.


Which java loops are entry controlled?

The for and while statements are entry-controlled loops. The do-while statement is an exit-controlled loop.


What is control loop?

An exit-controlled loop is a loop where the controlling conditional expression is evaluated at the end of each iteration, as opposed to an entry-controlled loop where the expression is evaluated at the beginning of each iteration. The upshot is that an exit-controlled loop always executes at least one complete iteration whereas an entry-controlled loop might not iterate at all: int x = 100; // entry-controlled loop while (x<50) { printf ("%d\n", x++); // won't execute at all because x<50 is false } // exit-controlled loop do { printf ("%d\n", x++); // will execute one time only } while (x<50);


What is meant by entry controled loop?

An exit-controlled loop is a loop where the controlling conditional expression is evaluated at the end of each iteration, as opposed to an entry-controlled loop where the expression is evaluated at the beginning of each iteration. The upshot is that an exit-controlled loop always executes at least one complete iteration whereas an entry-controlled loop might not iterate at all: int x = 100; // entry-controlled loop while (x<50) { printf ("%d\n", x++); // won't execute at all because x<50 is false } // exit-controlled loop do { printf ("%d\n", x++); // will execute one time only } while (x<50);


What does a condition controlled loop mean?

A condition-controlled loop is one that has an indefinite number of iterations; its opposite is the count-controlled loop. Condition-controlled loops execute until some event occurs, which is usually user-initiated. For example, modern programs run an condition-controlled loop similar to the following: while(GetMessage(message,hwnd,0,0)) { ... } This loop continues to execute until there are no messages left (the WM_QUIT message is returned, which has a value of zero). It is impossible to identify before execution the number of times such a loop will run, except during controlled tests, although you can easily identify what conditions will cause it to terminate.


What is the difference between entry and exit controlled loops - in Java?

while loop and for loop are entry controlled loops as they check looping condition at the entry point. do while loop is exit controlled loop as it checks looping condition at exit point. shreeradha@yahoo.com


How to complete this C plus plus End Of File controlled while loop program?

Add the missing parts.


What is a nested loop in java?

A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. The inner or outer loop can be any type: while, do while, or for. For example, the inner loop can be a while loop while an outer loop can be a for loop.


What are the similarities of while loop and a do while loop?

They both loop


What are some model question papers of plus one computer science?

1. ................is an alternative of if statement. 2. which of the following is an entry controlled loop? (a) for (b) switch (c) while (d) both b and c 3. which of the following is an entry controlled loop? (A) for (B) while (c)do while (d)both a and b (e)none of these 4.consider the given code fragment: const int n=25; int i=0,s=0; while(i { s+=i; i++; } cout<<s; write equivalent for loop for this. 5.write a programme to display the following output. 1 22 333 4444 55555 666666 6.write a programme to find the sum of digits of an integer number using (a) entry controlled loop (b) exit controlled loop


What is a sentenial loop?

It is a type of event controlled loop which is goes on until it strikes a value which is predefined to stop the loop.


Compare Do-While with While Statements?

A Do-While loop looks like this: do { loop body } while (condition); and a While loop looks like this: while (condition) { loop body } The main difference is that the loop body is always run once in the Do-While loop, then the condition is checked to see if the loop should keep running. In a While loop, the condition is checked first, and it will not run the loop body at all if the condition is false.