answersLogoWhite

0


Best Answer

A counted loop. Typically we use a for loop for counted loops:

// loop 10 times...

for (int i=0; i<10; ++i) {

// ...

}

We can also use while and do-while loops to do the same thing, however a for loop provides all the information up front where it belongs and we can localise the control variable. With while and do-while loops, the control variable must be declared outside the loop, and the increment is usually specified at the end of the loop. This makes while and do-while loops harder to read because the information that controls the loop is separated:

// loop 10 times...

int i = 0;

while (i<10) {

// ...

++i;

}

A do-while loop is similar to a while loop, but the control expression is placed at the end of the loop thus the loop always executes at least once. This also upsets the logic of a counted loop because the control variable is off-by-one.

// loop 10 times...

int i = 0; do {

// ...

++i;

} while (i<11);

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

while - loop and do-while loop.

Usage: while

while (condition) {

code

}

Usage: do-while

do {

code

} while (condition)

Difference - for do the code is first executed and then conditions is checked. Do will always execute at least once.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

while (! expression) statement;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What type of loop uses Boolean expression to control the number of times that it repeats a statement set of statements?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is flow control statement used in C programming?

Flow control statements are those statements that cause execution to branch or jump to a new section of code, often upon evaluation of some conditional expression (a decision statement such as an if or switch statement). The break, continue, goto and return statements are all flow-control statements. Function calls are not considered to be flow control statements since functions can be inline expanded (by the compiler) and would therefore follow the normal flow of execution.


Structure of If-Then statement?

if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;


What is the difference between ternary operators and if-else statement?

ternary is a single statement operator while even the most primary form of if else contains an if and an else statement. ternary only returns a value but if else can be used to do a lot of other things like printing, assigning values or just returning true or false.


What is the repetitive control structure in c plus plus?

C provides two sytles of flow control:BranchingLoopingBranching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching: Branching is so called because the program chooses to follow one branch or another.if statementThis is the most simple form of the branching statements. It takes an expression in parenthesis and an statement or block of statements. if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.? : OperatorThe ? : operator is just like an if ... else statement except that because it is an operator you can use it within expressions. ? : is a ternary operator in that it takes three values, this is the only ternary operator C has.switch statement:The switch statement is much like a nested if .. else statement. Its mostly a matter of preference which you use, switch statement can be slightly more efficient and easier to read. Using break keyword:If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement. This is achieved by using break keyword. Try out given example Show ExampleWhat is default condition:If none of the listed conditions is met then default condition executed. Looping Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way. while loopThe most basic loop in C is the while loop.A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statements get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again.This cycle repeats until the test condition evaluates to false. for loopfor loop is similar to while, it's just written differently. for statements are often used to proccess lists such a range of numbers: do...while loopdo ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once. break and continue statements C provides two commands to control how we loop: break -- exit form loop or switch.continue -- skip 1 iteration of loop.


Explain all the control statements in java?

The if and switch statements are commonly referred to as decision statements. When we use decision statements in our program, we're asking the program to evaluate a given expression to determine which course of action to take. It decides the control flow of the program.

Related questions

What does an IF Statement do?

An if statement is a control statement. It is used to control whether a statement executes or not, depending on whether a control expression evaluates true or false.if (expression) {statement;}In the above example, the expression is evaluated. If true, the statement executes, otherwise it does not.if (expression) {statement1;} else {statement2;}In the above example, the expression is evaluated. If true, statement1 executes otherwise statement2 executes.Note that if statements may be chained together using else if statements. The final else clause (if present) then becomes the default case. Also, any statement within an if statement may itself be an if statement, known as a nested if. If statements may be chained or nested to any depth.


Control statement in c plus plus?

Control statements are statements that alter the flow of execution according to the evaluation of an expression (the condition). The C++ control statements are ifstatements, switch statements and the tertiary conditional operator, ?:.


What is flow control statement used in C programming?

Flow control statements are those statements that cause execution to branch or jump to a new section of code, often upon evaluation of some conditional expression (a decision statement such as an if or switch statement). The break, continue, goto and return statements are all flow-control statements. Function calls are not considered to be flow control statements since functions can be inline expanded (by the compiler) and would therefore follow the normal flow of execution.


Structure of If-Then statement?

if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;


Can you treat all control flow statement as a function which is called by main function?

No,you can't. Statements and functions are totally different. Control flow statements are used to control the flow of application depending on some sort of Boolean condition and functions are used to do some sort of functionality (work)which your application needs.


What is difference between control statements and looping statements in c language?

differance between control statement and looping statement?


How do you use for loop in c?

The for loop in C, and C++ and Java, is defined as ...for (init-expression, limit-expression, loop-expression) statement;The init-expression is evaluated once. Then the limit-expression is evaluated. If it is true, the statement is evaluated, which can be a block of statements, or even a null statement, otherwise, control transfers out of the loop. If the statement is executed, then the loop-expression is evaluated, and control transfers back to the limit-expression.As an example, to print the numbers 1 through 10 ...for (int i = 1; i


What is the difference between ternary operators and if-else statement?

ternary is a single statement operator while even the most primary form of if else contains an if and an else statement. ternary only returns a value but if else can be used to do a lot of other things like printing, assigning values or just returning true or false.


What is the difference between do while and while in C language?

WhileDo-While1. In this statement, the Boolean expression is checked before executing the loop body.1. In this statement, the Boolean expression is checked after executing the loop body for the first time.2. It doesn't execute its statement if the condition fails.2. It will execute its statements at least once even if the condition fails. After that if the condition founds false the execution stops.It is mainly used in menu like programs where all the available choices are printed at least once.3. General loop form iswhile (condition){statements}3. General loop form isdo{statements} while (condition)4. Executing a code at least once tend to be relatively rare, thus the simple while is more commonly used4. This used for a block of code that must be executed at least once5. While loop is entry control loop5. Do while is exit control loop


What is the repetitive control structure in c plus plus?

C provides two sytles of flow control:BranchingLoopingBranching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching: Branching is so called because the program chooses to follow one branch or another.if statementThis is the most simple form of the branching statements. It takes an expression in parenthesis and an statement or block of statements. if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.? : OperatorThe ? : operator is just like an if ... else statement except that because it is an operator you can use it within expressions. ? : is a ternary operator in that it takes three values, this is the only ternary operator C has.switch statement:The switch statement is much like a nested if .. else statement. Its mostly a matter of preference which you use, switch statement can be slightly more efficient and easier to read. Using break keyword:If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement. This is achieved by using break keyword. Try out given example Show ExampleWhat is default condition:If none of the listed conditions is met then default condition executed. Looping Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way. while loopThe most basic loop in C is the while loop.A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statements get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again.This cycle repeats until the test condition evaluates to false. for loopfor loop is similar to while, it's just written differently. for statements are often used to proccess lists such a range of numbers: do...while loopdo ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once. break and continue statements C provides two commands to control how we loop: break -- exit form loop or switch.continue -- skip 1 iteration of loop.


Explain all the control statements in java?

The if and switch statements are commonly referred to as decision statements. When we use decision statements in our program, we're asking the program to evaluate a given expression to determine which course of action to take. It decides the control flow of the program.


Definition and comments for loop?

The C and C++ for loop is defined as...for (init-expression; test-expression; loop-expression) loop-statement;The init-expression is executed once.At the top of the loop, test-expression is evaluated. If it is false, control passes to the statement following loop-statement.The loop-statement is executed. It may be one statement, it may be a block of statements, or it may be no statement. If it is no statement, the semi-colon is required.At the bottom of the loop, loop-expression is executed, and then control passes to the test-expression at the top of the loop for another go-around.Each of init-expression, test-expression, and loop-expression may be missing. The semi-colons are required. The formal "forever" loop is for (;;) loop-statement; in which case the only way out is the break statement.Since each of init-expression, test-expression, and loop-expression can have side-effects, sometimes a loop is constructed with no loop-statement, and all processing is done between the parentheses.If test-expression is initially false, loop-expression and loop-statement are never executed. The init-expression is always executed only one time, and test-expression is executed at least one time.At any point during loop-statement, the breakstatement will exit to the statement following loop-statement, and the continue statement will jump to the loop-expression at the bottom of the loop.