Goto main content

break

Stops execution of a loop

BREAK

NAME

break - Stops execution of a loop

SYNOPSIS

break;

DESCRIPTION

This statement is used to stop the execution of a loop. It can be used with "for(1)", "while(1)" or "do until".

break 1; to break one loop. break 3 to break three levels of loops.

EXAMPLES

Note: In the following examples, the _ between the { should be removed to make it work.

 res={_{
                i=5;
                while i>0 do
                          i--; i;
                          if i==2 then break; endif
                endwhile
        }}.
        retourne res=432.

        res={_{
                j=10;
                while j>5 do
                          j--; j;
                          if j==7 then break; endif
                          i=5;
                          while i>0 do
                                        i--; i;
                                        if i==2 then break; endif
                          endwhile
                          'fini';
                endwhile
                'finj';
        }}. retourne res=9432fini8432fini7finj.

        res={_{
                i=5;
                do
                   i--;
                   i;
                   if i==2 then break; endif
                until i<0;
        }}. retourne res=432.

        res={_{
                j=10;
                do
                   j--; j;
                   if j==7 then break; endif
                   i=5;
                   do
                          i--; i;
                          if i==2 then break; endif
                   until i<0;
                   'fini';
                until j<0;
                'finj';
        }}. retourne res=9432fini8432fini7finj.

        res={_{
                for(i=0,j=4;i<5;++i,--j)  do
                    i; j;
                        if i==2 then break; endif
                endfor
        }}. retourne res=041322.

        res={_{
                for(i=0;i<5;++i) do
                    i;
                        if i==2 then break; endif
            for(j=10;j>0;--j)  do
                            j;
                                if j== 7 then break; endif
                        endfor
                endfor
        }}. retourne res=0109871109872.


        res={_{
                i=5;
                for j test(i,2)  do
                        i--;
                        "i=";
                        i; ','; sn_nb; ','; j;
                        if (i==2) then break; endif
                endfor
        }}. retourne res=\(5,2\)i=4,0,7\(4,2\)i=3,1,6\(3,2\)i=2,2,5.

        res={_{
                function f(i)
                        "i="; i;
                        sn_var = i*2;
                        return i>5;
                endfunction
                k=10;
                for j f(k)  do
                    "j="; j;
                     if (k==8) then
                                 break;
                         endif
                    k--;
        endfor
        }}. retourne res=i=10j=20i=9j=18i=8j=16.

SEE ALSO

AUTHOR

Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

Edit

© 2021 extenso Inc. All rights reserved.