Download MetaTrader 5

Operator While and boolean operation OR (||)

To add comments, please log in or register
Finoli
12
Finoli  

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.

honest_knave
Moderator
2423
honest_knave  
while(n<6 && BooleanFlag==False)
Finoli
12
Finoli  
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?

honest_knave
Moderator
2423
honest_knave  
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 

Khaled Mohamed
2502
Khaled Mohamed  

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

Irwan Adnan
929
Irwan Adnan  
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