answersLogoWhite

0

//Both loops will print out the alphabet {A-Z}

int i = 65;

while(i<65+26)

{

System.out.println((char)i);

i++;

}

...

for(int i=65; i<65+26; i++)

System.out.println((char)i);

As you can see, both loops accomplish the same thing. A while loop simply has a conditional statement that tells the loop what needs to be true for it to keep on looping.

A for loop is more concise: it has 3 parts: a starting value, a conditional statement, and a(n) action for what the loop should do after every iteration (in this case increase i by 1).

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

What is difference between for loop and do-while loop?

The do loop is similar to the forloop, except that the expression is not evaluated until after the do loop's code is executed. Therefore the code in a do loop is guaranteed to execute at least once. The following shows a do loop in action: do { System.out.println("Inside do while loop"); } while(false); The System.out.println() statement will print once, even though the expression evaluates to false. Remember, the do loop will always run the code in the loop body at least once. Be sure to note the use of the semicolon at the end of the while expression.


What does a while loop do in javascript?

a while-loop in javascript executes a section of code while a condition is true. Eg. function () { var i = 0; while (i &lt; 326) { alert(i++) } } In the above example, the an alert is given, showing the value of i so for as long as i is less than 326. In each loop, i is increased by 1.


How can you write a c program using while loop that will print first ten odd numbers?

#include&lt;stdio.h&gt; int main () { int odd=1; int count=0; while (count++&lt;10) { printf (%d\n", odd); odd+=2; } return 0; }


What is nesting loop?

Nested loop, you mean; one loop in the other loop, eg: for (i=0; i&lt;10; ++i) { for (j=0; j&lt;i; ++j) { printf ("i=%d, j=%d\n", i, j); } }


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.

Related Questions

Is it possible to use a for loop in place of a while loop?

Yes. while loop consist of only condition statement to make for loop look as while loop we can use syntax shown below: for(;condition;) eg: for(;i&lt;=n;)


What is difference between for loop and do-while loop?

The do loop is similar to the forloop, except that the expression is not evaluated until after the do loop's code is executed. Therefore the code in a do loop is guaranteed to execute at least once. The following shows a do loop in action: do { System.out.println("Inside do while loop"); } while(false); The System.out.println() statement will print once, even though the expression evaluates to false. Remember, the do loop will always run the code in the loop body at least once. Be sure to note the use of the semicolon at the end of the while expression.


What does a while loop do in javascript?

a while-loop in javascript executes a section of code while a condition is true. Eg. function () { var i = 0; while (i &lt; 326) { alert(i++) } } In the above example, the an alert is given, showing the value of i so for as long as i is less than 326. In each loop, i is increased by 1.


How can you write a c program using while loop that will print first ten odd numbers?

#include&lt;stdio.h&gt; int main () { int odd=1; int count=0; while (count++&lt;10) { printf (%d\n", odd); odd+=2; } return 0; }


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 is forloop?

For loop is utilize to do any specific work for specific number of times For example to print hello on computer screen 10 time we use For (start = 1; end = 10; start++) count&lt;&lt;"hello"; next


What is nesting loop?

Nested loop, you mean; one loop in the other loop, eg: for (i=0; i&lt;10; ++i) { for (j=0; j&lt;i; ++j) { printf ("i=%d, j=%d\n", i, j); } }


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.


The while loop is a type of loop?

Is loop


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


Definition of do loop while in visual basic?

There are 3 type of loop 1 is for loop 2 is loop while 3 is loop untile

Trending Questions
Is petroleum energy in widespread use? What is the force directed along the ropes of a rope and pulley system? What ways are the construction industry reducing the impact it has on the natural environment? What are the advantages and disadvantages of project Tiger? Why was the bessemer process necessary? What is advantage and disadvantages of multistage amplifier? Who was the first person to die performing electric experiments? Can a conditional operator replace an if statement always? How much power is needed to supply the losses associated with the production of the magnetic field in a 3-phase motor? What simple machines are found in a vegetable peeler? Describe three different ways that a power company might produce steam to turn a turbine? Can a derived class make a public base function private true or false? How do you design drawing of a surge tank? Why are the primary colors in TVs red blue and green? A transformer is rated at 12V-0-12V and 250mA so what does the 250mA mean and how do you calculate the fuse for the primary winding without knowing the VA rating? What is this native code and what is difference between native code and machine code? Why is it important that as a program designer that you correctly identify the type of data for a variable and give the variable a logical name? What are some ductile materials? What is the difference between self assembly and self organization? IS HTML and JavaScript only differ in where the script is interpreted?