While loop with multiple conditions in C++

ConMaki picture ConMaki · May 15, 2013 · Viewed 58.8k times · Source

How would I make a loop that does the loop until one of multiple conditions is met. For example:

do
{
    srand (time(0));
    estrength = rand()%100);

    srand (time(0));
    strength = rand()%100);
} while( ) //either strength or estrength is not equal to 100

Kind of a lame example, but I think you all will understand.

I know of &&, but I want it to only meet one of the conditions and move on, not both.

Answer

Daniel Daranas picture Daniel Daranas · May 15, 2013

Use the || and/or the && operators to combine your conditions.

Examples:

1.

do
{
   ...
} while (a || b);

will loop while either a or b are true.

2.

do
{
...
} while (a && b);

will loop while both a and b are true.