Using the operator "BREAK" one after one

 

Hello friends,

I have aquation, and I nead your help:

If I have 2 "FOR" - loop, and I want to stop them together, Can I break the together with using the operator BREAK one after one?

Means at the following example: Is the GREEN BREAK breaks the the GREEN Loop, and the RED BREAK breaks the RED Loop?

Look at the folowing example:

for(cnt=0; cnt < OrdersTotal()-1; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderMagicNumber() == MAG && ......................... )
{
..

..
for(int kg=0; kg < OrdersTotal(); kg++)
{
OrderSelect(kg, SELECT_BY_POS, MODE_TRADES);
if ( OrderMagicNumber() == MAG && ................. )
{
Sum_prof = Prof1 + Prof2 + OrderProfit();
....................................................... ........... .. . .

break;
break;
}
}
}
}
Thanks for your help.

(N.B. If the answer is NO, Do you have any idea to overcome this "technical problem"?

Y.

 

Please use this to post code . . . it makes it easier to read.

 
RaptorUK:

Please use this to post code . . . it makes it easier to read.


Thanks Raptor,

The code is 3691 lines... .

I think that with the color lines it is quit understandable. Isn't it?

 
crossy:


Thanks Raptor,

The code is 3691 lines... .

I think that with the color lines it is quit understandable. Isn't it?

Can't you just edit you post add a SRC section and add in your code snippet . . you don't need to add all the code.

 
I don't think break will work as you have it . . . I think you need to have the 2nd break outside of the first loop, maybe set a bool SecondBreak = true just before the first break and then do the 2nd break n the outer loop if SecondBreak
 
RaptorUK:
I don't think break will work as you have it . . . I think you need to have the 2nd break outside of the first loop, maybe set a bool SecondBreak = true just before the first break and then do the 2nd break n the outer loop if SecondBreak


Great, you rigth.

Thank You!!

 
crossy:
If I have 2 "FOR" - loop, and I want to stop them together, Can I break the together with using the operator BREAK one after one?

  1. No. But what you posted, in the inside loop is not dependent on the outside one. Move the inside out.
  2. Just check if the inside loop finished properly or not.
    for(cnt=0; cnt < OrdersTotal()-1; cnt++){
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
        if ( OrderMagicNumber() == MAG && ......................... ){
            :
            int KgLimit = OrdersTotal();
            for(int kg=0; kg < KgLimit; kg++){
                OrderSelect(kg, SELECT_BY_POS, MODE_TRADES);
                if ( OrderMagicNumber() == MAG && ................. ){
                    Sum_prof = Prof1 + Prof2 + OrderProfit();
                :
                break;  // Exit kg loop
            }   // kg
            if (kg < kgLimit)  break;  // exit cnt loop
        :
    }   // cnt
    

Reason: