How to use while loops with an OR logical operator

Hi everyone,

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


bool BooleanFlag=False;

int n;

int start()


Alert("Program Start");

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


Alert("BooleanFlag  =",BooleanFlag);

Alert("n   =", n);




Alert("Program finish");




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.


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

Hello fuphamk,

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

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 :slight_smile:

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.