answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2008-05-06 19:34:03

while is a loop. The most common definition is

while (bool_condition)

{

...//your code here

}

where bool_condition is a variable of bool type or equality/unequality, for instance a==b, or a >= 0 and so. while woork as long as bool_condition has value true.

int index = 0;

while (index <10)

{

cout << index << endl;

index++;

}

This code will print on the screen all numbers from 0 to 9 including, when index equals 10 condition index < 10 becomes false and while passes the turn to the next element. The outcome of this code is:

0

1

2

3

4

5

6

7

8

9

each on a new line.

Also you can use the loop which is called do-while. It works different a little bit, and it looks like following:

do

{

//your code here

} while (bool_condition);

do

{

cout << index << endl;

index++;

} while (index <10);

The result will be

0

1

2

3

4

5

6

7

8

9

10

each on a new line. Difference between while and do-while is following. do-while alsways makes one extra loop because it checks bool condition after it ran the cycle, while loop does it before running the cycle. That's why you see one extra number 10 in outcome.

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Still Have Questions?

Related Questions

Is a routing number the same as a sort code?

Routing bank is the same as the sort code. UK banks use the sort code while the US banks use the routing number.


Difference between pin code and postal code?

There is not much of a difference between a pin code and a postal code. A pin code is used in India while other countries such as the U.S. use postal codes.


Can I use more than one budk coupon code at a time?

No, you can only use one BUDK coupon code per order. You can put your coupon code into the box for discount codes while you are in the check-out process.


What happens if you catch N's Zekrom with a cheat while it is still his?

if you use an action replay and use the steal trainers Pokemon code and the 999 masterball code then you can catch it with a masterball and then its your's.


How can you repeatedly execute a code in java script?

1) use for loop 2) do while loop


What is the police scanner code for mentally unstable?

It is common while discussing a mentally unstable acting person over the airwaves to use the code "5150".


What is the use of while loop in c program?

A while loop iterates over the same code block until the control expression evaluates false.


Is the runners warehouse discount code required to use a coupon for runners warehouse?

While purchasing at the runners warehouse with a coupon, you do have to have a discount code. The code determines if the coupon is valid or not. Without this code, your purchase will not go through.


How do you use Pokemon master code?

you use it to use other codes ex. the code you use disapears use a mater code it will work


How i met your mother code word?

Robin and Barney use the word "flugelhorn" as a code word to signal the other if they have gone too far physically while they are dating.


What is the code for the master code ruby?

if you wont to use a secred code you have to get the master code for ruby. ===&gt;vba==&gt;cheats==&gt;cheat list==&gt;game schark==&gt;use your master code and you can use a secred code!:)


What is the code to shark tooth island poptropica?

look at your translation key while you put in the code. what you're supposed to type is OPEN, but you have symbols, so use the translation key. :)


Why do the codes not work after a while on moshi monsters?

because they EXPIRE!! so if you get a code you have to use it straight AWAY!! also here is one code: moshidosh392 [dont know if it has expired}


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

while - loop and do-while loop.Usage: whilewhile (condition) {code}Usage: do-whiledo {code} while (condition)Difference - for do the code is first executed and then conditions is checked. Do will always execute at least once.


How do you add Pokemon black and white to an ar dsi?

either use the code manager or add as new game while it is inserted into your dsi while starting it up in your ds


How do you use the DSi Code Manager while using a DS Lite system?

Let's think for a moment, your asking how to use a Nintendo Dsi system on a Ds LITE.


Do you use the V70.0 diagnosis code with a 99369 code?

i use V72.31


Why Don't People Still Use Morse Code?

Morse code is still in use if you know where to look. Many ham radio operators around the world converse with "CW" (Morse code) on a regular basis. Listen around on a shortwave radio with "SSB/CW" capability for a little while and you'll hear lots of Morse code.


What code do you use on moshi monsters to get dj quake?

you dont use a code you use seeds


How do you rest the codes for your 2004 Mitsubishi Galant?

Use an OBDII code reader or a scan tool or try disconnecting the battery for a while.


How do you enter an imvu cheat code?

To type in imvu codes you push *use (the number) for example if you going to use code number 1 for an imvu t shirt you type in *use 1 and then push enter and it should come up it doesnt always work the first time. to remove a code do the same thing except type in remove instead of use for example *remove 1 and then press enter. One code i advise you not to use code number 8 (*use 8) because it turns your screen buttons into japenese and it take a while to remove it


Why should you avoid goto statement?

goto tends to get messy if you have to use more then one of them. It's very hard to upgrade as well as understand when goto is used in code. Some time ago it was a big discussion about it. Many professional programmers have agreed that goto caused a lot of problems. Nowadays goto is almost not used in professional projects.another view:You shouldn't "avoid it" so much as know when to use it and when to use another way. Used improperly it makes code unreadable and hard to maintain, which is why beginners are taught not to use it (beginners would use it improperly and never learn to use loops :p ). Example of the proper usage would be exiting multiple levels of nested loops.while(...){while(...){while(...){if (something) goto end;end://rest of the codeBut it can still be avoided. In this example, by using a flag.flag=1;while(...&&flag){while(...&&flag){while(...&&flag){if (something) flag=0;


What is code for Aloha Airlines?

The IATA code for Aloha Airlines is AQ while the ICAO code is AAH.


Can you use the Blingo moshling code twice?

No, you can only use the code once.


How do you use your pets code on petz nursery 2?

how do you use your pet code


Still have questions?