Hi,

break and continue are related but different commands. Break applies 
to all remaining iterations, continue applies to the current 
iteration.

Break will terminate the loop completely (i.e. stop executing the 
rest of the loop body, and move on to the statement immediately 
following the loop body, even if all values of the looping variable 
have not yet been iterated over).

Continue will terminate the current iteration (i.e. stop executing 
the rest of the loop body, but still restart from the beginning of 
the loop body at the next iteration of the looping variable).

In both cases, you would normally have conditional code to control 
what you want to do.

For example; in the code below, a trace will be printed when i == 1to 
8 except when i == 5 (continue without trace), and never reach i == 9 
to 10 since break will force an exit.

for (i = 1; i <= 10; i++) {
  if (i == 5) {
    continue;
  }
  _TRACE("i == " + i);
  if (i == 8) {
    break;
  }
}

For more information, run AmiBroker, click Help menu, click on Index 
tab and type in break. Do the same for continue.

Mike

--- In [email protected], "reinsley" <[EMAIL PROTECTED]> wrote:
>
> 
> Thank you Ed for your help.
> 
> I did not find the help documentation concerning break, not easy as
> the word break appears often in the domain of technical analysis.
> 
> Anyway, my poor programming knowlegde comes from VBA, so step by 
step
> and stop are missing me. Probably it's useless with more practice
> 
> without break, I get that :
> [1632] n1= 0
> [1632] n1= 1
> [1632] n1= 2
> [1632] n1= 3
> [1632] n1= 4
> [1632] n2= 5
> [1632] n2= 6
> [1632] n2= 7
> [1632] n2= 8
> [1632] n2= 9
> 
> with a break, this :
> [1632] n1= 0
> [1632] n2= 5
> [1632] n2= 6
> [1632] n2= 7
> [1632] n2= 8
> [1632] n2= 9
> 
> I wish :
> [1632] n1= 0
> 
> for( n = 0; n < 5; n++ )
> {
>     SinePlotter( n/2+Cum(0.01), n );
> _TRACE("n1= " + n);
> break;
> }
> 
> for( n = 5; n < 10; n++ )
> {
>   SinePlotter( n/2+Cum(0.01), n );
> _TRACE("n2= "+ n);
> }
> 
> What I would like is a real stop even out of a loop. Does it exist 
in
> the Ami world ?
> 
> Your answer to KBH about sub is helpful.
> 
> Regards
> 
> 
> --- In [email protected], "Ed Hoopes" <reefbreak_sd@> wrote:
> >
> > To stop code caught in an infinite loop try Shift+Break on the 
keyboard 
> > 
> > To stop  execution in the code stream use Break; It is covered in 
the
> > Help file. 
> > 
> > --- In [email protected], "reinsley" <reinsley@> wrote:
> > >
> > > I'am looking for a way to stop the code running.
> > > I saw break/continue statement for loop, unfortunately the 
links are
> > > broken.
> > > 
> > > http://www.amibroker.com/guide/v50/keyword/break.html
> > > http://www.amibroker.com/guide/v50/keyword/continue.html
> > > 
> > > Does it exist the equivalent statement to stop the code at a 
specific
> > > point ?
> > > If not, any trick to do it ?
> > > 
> > > Thanks
> > >
> >
>


Reply via email to