5133p39 16 Posted December 26, 2006 I need to break from a "while" loop, i now i can do it with the help of a simple boolean variable which value is later changed, causing the loop condition to be false: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_done = false; while{ not _done } do { _done = true; }; ...but it would fit better my nit-picking nature if i could use some sort of 'break' command, instead of wasting resources by initializing more and more unnecessary variables. On Biki i found two commands - breakOut and breakTo, but i can't figure how to use them. What exactly is their purpose? Share this post Link to post Share on other sites
kegetys 2 Posted December 26, 2006 They seem to work like this: This counts to five: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _x = 0; while{true} do { Â scopeName "myLoop"; Â _x = _x + 1; Â hint format["%1", _x]; Â sleep(0.25); Â if(_x == 5) then {breakOut "myLoop"}; }; And this does the same thing: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> scopeName "myRoot"; _x = 0; while{true} do { Â _x = _x + 1; Â hint format["%1", _x]; Â sleep(0.25); Â if(_x == 5) then {breakTo "myRoot"}; }; Share this post Link to post Share on other sites
5133p39 16 Posted December 26, 2006 @Kegetys: I am speechless... THANK YOU! Share this post Link to post Share on other sites
snkman 351 Posted January 4, 2008 Damn it!!! So breakTo is doing something like a jump (#) If i just could now this bevore then i could save a lot lot lot of time... Share this post Link to post Share on other sites
sickboy 13 Posted January 4, 2008 Damn it!!!So breakTo is doing something like a jump (#) If i just could now this bevore then i could save a lot lot lot of time... If I Interpret http://community.bistudio.com/wiki/breakTo correctly, breakTo breaks back "into" the scope named at breakto. So it probably doesn't jump to before the while loop at the place where the scope is defined, but in fact "returns" to the scope, and as such it doesn't jump, but just exits the while loop in Kegetys his example. Interpreting his post, he seems to state the same. Share this post Link to post Share on other sites
barmyarmy 0 Posted January 4, 2008 Also consider exitWith which will exit from a foreach loop, which allows you to do things like.... foundThing=objNull; { currentThing=_x; if ( _x == _anotherThing) exitWith{ foundThing=_x; }; } foreach things; Share this post Link to post Share on other sites
vova _fox 0 Posted January 5, 2008 array call func func= { try { _this call func2; } catch { hint _exception; }; }; func2= { { if (errorcondition) then {throw "error ....."}; } foreach _this; }; Share this post Link to post Share on other sites