answersLogoWhite

0


Best Answer

A "while" loop is appropriate in this case - one in which the condition is evaluated at the beginning of the loop.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What type of loop uses a boolean expression?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What type of loop uses Boolean expression to control the number of times that it repeats a statement set of statements?

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);


The int data type requires more memory than the double data type?

No, the int variable uses less memory, and therefore it is preferable to use an int rather than a double where you can.A boolean variable uses even less memory, but obviously is useful only in limited circumstances.


What feedback does a close loop servo mechanism uses?

kidney


How do you work loop in java?

A for loop works similarly to most programing languages. An example of a for loop isfor(i=0; i 3; y++) { }The declaration and initialization happens before anything else in a for loop. And whereas the other two parts-the boolean test and the iteration expression-will run with each iteration of the loop, the declaration and initialization happens just once, at the very beginning. You also must know that the scope of variables declared in the for loop ends with the for loop! The following demonstrates this:for (int x = 1; x < 2; x++) { System.out.println(x); // Legal } System.out.println(x); // Not Legal! x is now out of scope If you try to compile this, you'll get something like this: Test.java:19: cannot resolve symbol symbol : variable x location: class Test System.out.println(x); ^Basic for Loop: Conditional ExpressionThe next section that executes is the conditional expression, which (like all other conditional tests) must evaluate to a boolean value. You can have only one logical expression, but it can be very complex. Look out for code that uses logical expressions like this:for (int x = 0; ((((x < 10) && (y-- > 2)) | x == 3)); x++) { }The preceding code is legal, but the following is not:for (int x = 0; (x > 5), (y < 2); x++) { } // too many //expressions The compiler will let you know the problem: TestLong.java:20: ';' expected for (int x = 0; (x > 5), (y < 2); x++) { } ^ The rule to remember is this: You can have only one test expression. In other words, you can't use multiple tests separated by commas, even though the other two parts of a for statement can have multiple parts.Basic for Loop: Iteration ExpressionAfter each execution of the body of the for loop, the iteration expression is executed. This is where you get to say what you want to happen with each iteration of the loop. Remember that it always happens after the loop body runs! Look at the following:for (int x = 0; x < 1; x++) { // body code that doesn't change the value of x } The preceding loop executes just once. The first time into the loop x is set to 0, then x is tested to see if it's less than 1 (which it is), and then the body of the loop executes. After the body of the loop runs, the iteration expression runs, incrementing x by 1. Next, the conditional test is checked, and since the result is now false, execution jumps to below the for loop and continues on. Keep in mind that barring a forced exit, evaluating the iteration expression and then evaluating the conditional expression are always the last two things that happen in a for loop! Examples of forced exits include a break, a return, a System.exit(), or an exception, which will all cause a loop to terminate abruptly, without running the iteration expression. Look at the following code: static boolean doSomething() { for (int x = 0; x < 3; x++) { System.out.println("in for loop"); return true; } return true; } Running this code produces in for loop The statement only prints once, because a return causes execution to leave not just the current iteration of a loop, but the entire method. So the iteration expression never runs in that case. Basic for Loop: for Loop Issues None of the three sections of the for declaration are required! The following example is perfectly legal (although not necessarily good practice): for( ; ; ) { System.out.println("Inside an endless loop"); } In the preceding example, all the declaration parts are left out so the for loop will act like an endless loop. For the exam, it's important to know that with the absence of the initialization and increment sections, the loop will act like a while loop. The following example demonstrates how this is accomplished: int i = 0; for (;i


Which pair of loops causes a statement or set of statements to repeat as long as a condition is true?

A while loop repeats until the condition becomes false, and may never execute: int a = 4; while (a &gt; 5) { //Do something } or int a = 4; while (a &gt; 0) { //Do something a--; }

Related questions

Uses of Boolean Algebra?

Boolean Algebra is a type of math in which the values of the variables are true and false. The algebra is the basis for digital logic, computer programming and mathematical logic.


What type of loop uses Boolean expression to control the number of times that it repeats a statement set of statements?

A counted loop. Typically we use a for loop for counted loops: // loop 10 times... for (int i=0; i&lt;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&lt;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&lt;11);


What is the difference between If-else and Switch-case in Java?

The if statement is used to select among two alternatives. It uses a boolean expression todecide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternativeshould be executed.


How 'if' statement is different from a 'switch' statement in C language?

The if statement is used to select among two alternatives. It uses a boolean expression todecide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternativeshould be executed.


What are the uses of Boolean algebra?

One use of Boolean algebra is to minimize any function or logic gate.


What is boolean query?

A boolean query is a query that uses a boolean conditional.E.g., an overtime formula would be(hours-40)(hours>40)The boolean expression would multiply the first result by 1 if hours is greater than 40, and, by 0 otherwise. This would prevent a negative overtime calculation.The result would be the same as=if(hours>40, hours-40,0)krazykyngekorny(at)gmail.com


What numbers are used in Boolean algebra?

Boolean algebra uses the numbers 0 and 1 to represent statements which are False and True respectively.


For loop -uses?

You can use a for loop whenever you can use a while loop; it's the same.


What has the author G F South written?

G. F. South has written: 'Boolean algebra and its uses' -- subject(s): Boolean Algebra, Switching theory


What is a band printer?

A band printer is a line printer that uses a metal band, or loop, of type characters as its printing mechanism.


What is Band printer?

A band printer is a line printer that uses a metal band, or loop, of type characters as its printing mechanism.


What is a Boolean condition?

A boolean is a value which can either be true or false. A boolean condition is mathematical equation where the result is a boolean (either true or false). Often used in programming.A boolean condition consists of some varibles, and boolean operations that can be carried out using them. Here are some boolean operations. The sybols are those used in Java and C++.> Greater Than. Returns true when the number before > is greater than the number after< Less Than. The opposite of Greater than== Equals. If the values are equal returns trueOR Returns true if the boolean before and/or the boolean after is true&& AND Returns true only if the boolean before AND after the && are true! NOT Inverts/NOT's a boolean. True becomes false. False becomes trueMost programming languages have booleans as a type of variable and if statements as control flow.An if statement uses a boolean to decide whether or not something is run eg.if(someBoolean){// If some boolean is true this peice of code will be run}A an example of a boolean condition could use a less than or greater than symbolif( someNumber > 9000 ) {print( "The number... it's.... OVER 9000!!" );}