answersLogoWhite

0


Best Answer

Perhaps you meant something like this:

i=1-1; while (++i<=10) { printf ("%d\n"); } /* 1..10 */
i=10+1; while (--i>=1) { printf ("%d\n"); } /* 10..1 */

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you make a while loop go backwards?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When should use a while loop over a do loop?

Generally speaking a for loop looks like this:for(Initialization;condition;increment){Do Stuff}whereas a while loop looks like this:while(condition){Do Stuff}Before the while loop there should be some initialization and somewhere in the Do Stuff section there should be statements that change the condition. Those statements are analogous to the increment section of the for loop.


What are the types of loops?

There are three forms of loop commonly used in C/C++, the for loop, the while loop and the do-while loop. The for loop is most commonly used whenever an action is going to be performed a set amount of times. For example, to sum every element in an array: for(i = 0; i &lt; arraySize; i++) { sum = sum + array[i]; } The while loop and do-while loop are commonly used to loop until a condition is met. The difference between the two is that the do-while loop goes through one iteration before checking its condition, while the while loop checks its condition before any execution of the loop. Example do-while loop: do { randomNumber = rand() % 10; }while(randomNumber != 6); Example while loop: cout &gt; number; while(number &lt; 0) { cout &gt; number; }


What is a while statement in turbo c plus plus?

A while statement is one type of looping statement. by which we can start a loop in our programs. while loop is precondition checking statement, because it first check its condition then loop will go to its body part. EX. while(i&gt;0) { //body part } here when i will &gt;0 then it will check it body part and execute it and display result.


What is the difference between a repeat until and a while do loop?

Repeat until loops run until a condition is true. They repeat at the end of the loop and they will always run at least once. While do loops will only run while a condition is true. They may not run at all.


Why does java script support more than one type of loop?

Think of a Javascript loop as a loop in a rollercoaster, which, as you know, makes you go back to the place you started the loop, and then continue. Javascript allows you to create sections of code that make the program handler to go back to the point specified, so instead of copying out a functions directions twice, you can tell the program to reference that section of code for the instructions, and then jump back to where it was.

Related questions

How do you make a H in cursive?

First you make a cane. Then, 1cm after the cane, make a backwards cane. As you come up loop to the first cane and make the loop stretch beyond the backwards cane.


How do you convert a while loop to do-while loop?

A for loop is classified as an iteration statement. A simple example might be... For x = 1 To 10 'loop body Next x The same loop expressed as a while loop (classified as a control flow statement) could be... x = 0 Do While x &lt; 11 'loop body x = x + 1 Loop .


What is the difference between while loop and for loop in matlab?

A while loop executes code inside the while block continuously until the said condition is not true. A for loop contains three parts. The first part is carried out prior to the for loop, the middle part is executed by the for loop until it is no longer true, and the final part is performed at the end of each go round of the loop.


When should use a while loop over a do loop?

Generally speaking a for loop looks like this:for(Initialization;condition;increment){Do Stuff}whereas a while loop looks like this:while(condition){Do Stuff}Before the while loop there should be some initialization and somewhere in the Do Stuff section there should be statements that change the condition. Those statements are analogous to the increment section of the for loop.


What are the types of loops?

There are three forms of loop commonly used in C/C++, the for loop, the while loop and the do-while loop. The for loop is most commonly used whenever an action is going to be performed a set amount of times. For example, to sum every element in an array: for(i = 0; i &lt; arraySize; i++) { sum = sum + array[i]; } The while loop and do-while loop are commonly used to loop until a condition is met. The difference between the two is that the do-while loop goes through one iteration before checking its condition, while the while loop checks its condition before any execution of the loop. Example do-while loop: do { randomNumber = rand() % 10; }while(randomNumber != 6); Example while loop: cout &gt; number; while(number &lt; 0) { cout &gt; number; }


Do snakes make you go backwards in snakes and ladders?

They make you go down the board, ladders make you go up towards the finish.


How do you flip an array without using flip function in PHP?

Use a for-loop starting at the length of the array and go backwards and build up a new array with the values.


What is a double loop?

A double loop is a figure skating jump in which you go into doing backwards crossovers, hook or turn your foot, jump with feet first arms second and rotate twice in the air before landing on the outside edge that you jumped off of.


Can a clock go backwards?

No, it can't go backwards


What is a while statement in turbo c plus plus?

A while statement is one type of looping statement. by which we can start a loop in our programs. while loop is precondition checking statement, because it first check its condition then loop will go to its body part. EX. while(i&gt;0) { //body part } here when i will &gt;0 then it will check it body part and execute it and display result.


When do the clocks go backwards an hour?

does the clock go backwards


Which is more good to use for loop or while loop?

The main difference comes into picture when you use continue with them i.e. for and while. In a while loop if continue is used before the increment of a variable is done it converts into a infinite loop. i=1; while(i&lt;10) { /* do stuff */ if(i==6); continue; i++; } The above piece of code will turn into an infinite loop. for(i=1;i&lt;10;i++) { /* do stuff */ if(i==6); continue; } In the above for loop the value of will be incremented once it attains the value 6. Therefore it will not turn into a infinite loop. Cheers. astvansh&gt; 'for' statement takes the start condition, stop condition, and the increment. 'while' statement just takes the stop condition. One scenario (which i can think of) where while 'needs' to be used rather than a for, would be when the counter needs to be incremented/decremented conditionally... string[] arr = {"a", "b", "b", "c"}; int i = 0; while( i&lt; 10) { // do something constructive if(arr[i] == "b") { i = i + 2; } else { i++; } } Cheers, Ajeesh Another main difference between the two: a 'for' loop is called a determinate loop, meaning that we usually use it when we know ahead of time how many iterations we want. The 'while' loop is an 'indeterminate' loop, because we usually use it in situations where we do not know the number of times the loop may iterate.