Log in

View Full Version : break;



zluo
06-01-2012, 04:59 AM
i want to clear something up. how is break; used? can it be used to exit out of an entire procedure?

Runaway
06-01-2012, 05:00 AM
Exit; is for exiting from a procedure/function. Break; is for exiting from a (for..to..do, while..do, repeat..until) loop.

riwu
06-01-2012, 05:02 AM
it is used to break out of a loop, and then continue with the rest of the procedure. Eg.
repeat
wait(100);
if (condition1) then break;
if (condition2) then break;
until(false);

which is the same as:
repeat
wait(100);
until (condition1) or (condition2);
so its more suitable for
for to do loops

zluo
06-01-2012, 05:06 AM
if you do exit; would it exit out and enter the next procedure on the mainloop or onto the next procedure after the one just exited? thanks for the responses

Runaway
06-01-2012, 05:07 AM
if you do exit; would it exit out and enter the next procedure on the mainloop or onto the next procedure after the one just exited? thanks for the responses

It exits out of the entire procedure/function that it's called in. So yes, it would move onto whatever is called after it in a main loop/other function.

riwu
06-01-2012, 05:10 AM
if you do exit; would it exit out and enter the next procedure on the mainloop or onto the next procedure after the one just exited? thanks for the responses
Whats the difference between what u said? :garfield:

U mean the procedure base on the order of the script?
i.e.
procedure abc1;
begin
end;

procedure abc2;
begin
if cond1 then exit;
//it will exit to the nxt proc based on ur mainloop, in this case abc1
end;

procedure abc3;
begin
end;

//mainloop
begin
abc2;
abc1;
abc3;
end.

zluo
06-01-2012, 05:21 AM
thanks for clearing this up