The use of the "break" operator

To add comments, please log in or register
Ernest Klokow
1169
Ernest Klokow  

I am busy writing my first EA and I have certain conditions that I check for false or true. The results are stored in an array.

The array has 5 instances. If only one instance is false it must make the total result also false. To get a true result ALL five instances must be true.

I am not familiar with the "break" operator which I am using in the following code to determine if the final result should be true or false:


for (i=1; i<=5; i++)

if (bTradeArray[i]==true) bTrade = true;

else bTrade = false;

break;

I want to escape the loop as soon as I get the first false result.

Can anyone PLEASE help me?

whroeder1
17927
whroeder1  

  1. The array has 5 instances.
    for (i=1; i<=5; i++)
    If bTradeArray is defined as bool bTradeArray[5] then it has 5 instances 0 to 4 not 1 to 5
  2. I want to escape the loop as soon as I get the first false result.
    for (i=0; i<5; i++) if (!bTradeArray[i]) break;
    if (i<5){ // one or more false
    }
    else{ // all are true.
    }
    
Ernest Klokow
1169
Ernest Klokow  
WHRoeder:

  1. The array has 5 instances.
    for (i=1; i<=5; i++)
    If bTradeArray is defined as bool bTradeArray[5] then it has 5 instances 0 to 4 not 1 to 5
  2. I want to escape the loop as soon as I get the first false result.

Thank you WHRoeder! MUCH obliged!!! You saved me many hours of time!
To add comments, please log in or register