# Operator While and boolean operation OR (||)

To add comments, please log in or register
12

Hi everyone,

could i use the boolean operation OR (||) into a While cycle?, i.e:

------------------------Example-------------------------

bool BooleanFlag=False;

int n;

int start()

{

Alert("Program Start");

while(n<6 || BooleanFlag==False)

{

Alert("BooleanFlag  =",BooleanFlag);

Alert("n   =", n);

BooleanFlag=True;

n++;

}

Alert("Program finish");

n=0;

return(0);

}

----------------------------------------------------------

When i try to program something like this, the cycle while just operates on the n<6 condition, bypassing the 2dn one or the || condition.

if you change the order of the condition,

While(BooleanFlag==False || n<6)

the result is the same.

Thanks.

Moderator
2423

`while(n<6 && BooleanFlag==False)`
12

honest_knave:
while(n<6 && BooleanFlag==False)

Hello honest_knave,

thanks for your answer

i want a OR condition into a While cycle; continue the cycle until expression1 OR expression2 happens. it is possible? so it is, how?

if i use && condition, the cycle while will execute until both expression 1 and expression 2 happens.

or im wrong?

Moderator
2423

Finoli:

Hello honest_knave,

thanks for your answer

i want a OR condition into a While cycle; continue the cycle until expression1 OR expression2 happens. it is possible? so it is, how?

if i use && condition, the cycle while will execute until both expression 1 and expression 2 happens.

or im wrong?

You need the loop to continue while n<6 and BooleanFlag==False

Try it

2502

Don't type "True" and "False"

but: "true" and "false"

All must be small letters,

you can tell me if still there is any problem :)

929

`while(n<6 || BooleanFlag)`

BooleanFlag is a boolean variable so it is no need to include equation. Offcourse you have to initialize it first like in your example program. It does not matter using small or capital or mixed letters.

The loops itself will be processed if the condition is TRUE. So BooleanFlag must be initialized TRUE if you want to process the loop OR while n<6.

To add comments, please log in or register