Jump to content
Sign in to follow this  
5133p39

breakOut, breakTo - related to While?

Recommended Posts

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

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

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
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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×