answersLogoWhite

0

How do you use the while code?

User Avatar

Anonymous

17y ago
Updated: 8/16/2019

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.

User Avatar

Wiki User

17y ago

What else can I help you with?

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.


Can add on code 90785 be use with 90847?

Yes, code 90785 can be used in conjunction with code 90847. Code 90785 is for the use of interactive complexity in psychotherapy, while code 90847 is for family psychotherapy when the patient is present. When billing, ensure that the documentation supports the use of both codes, and verify payer policies, as some insurers may have specific guidelines regarding code combinations.


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".


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.


I would like to knowwich code can I use to unlock my receiver Euro-box while someone locked itThanks in advance waiting your help?

I would like to know ,wich code can I use to unlock my receiver;while someone locked it.Thanks in advance,waiting your help.


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.


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


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. :)