break (level);
Posted: Fri Jun 09, 2006 3:07 am
In some occasions it would be handy to have the break statement leaving not only the loop it currently is in, but also the loop wrapping the current one and the one wrapping that... uhm... i guest my english isn't sufficient to epxlain what I mean. This code hopefully better explains it:
One already can pass the name of a label as a parameter to the break statement, but the label this points to has to be definded before the break statement. It would be a lot more useful if labels could be defined in the code somewhere before or after the break statement. But since using absolute jumps (ore whatever is the correct term for it) isn't the smartes way to code, break <level>; would be way better.
Code: Select all
// I want to leave both for-endfor loops
// instead of having to do something like this:
program test(who)
var spot:= array {};
var x;
var y;
for (x:= (who.x - 5); x <= (who.x + 5); x:= x + 1)
for (y:= (who.y - 5); y <= (who.y + 5); y:= y + 1)
if (GetWorldHeight (x, y) == 0)
spot:= array {x, y};
break; ---------+
endif |
endfor |
|
if (spot.size () > 0) <-----------+
break; ------------+
endif |
endfor |
|
SendSysMessage (who, "" + spot); <--+
endprogram
// I'd like to be able to do this:
program test(who)
var spot:= array {};
var x;
var y;
for (x:= (who.x - 5); x <= (who.x + 5); x:= x + 1)
for (y:= (who.y - 5); y <= (who.y + 5); y:= y + 1)
if (GetWorldHeight (x, y) == 0)
spot:= array {x, y};
break 2; ---------+
endif |
endfor |
endfor |
|
SendSysMessage (who, "" + spot); <--+
endprogram