Re: "break" equivalent in Macro language.
Posted by Michael Ellis on Dec 07, 2010; 2:31pm
URL: http://imagej.273.s1.nabble.com/break-equivalent-in-Macro-language-tp3686262p3686268.html
Setting i to 1e99 (a very large value much greater than 10 is what causes the loop to terminate when the next executes the conditional test i < 10.
On 7 Dec 2010, at 14:07, Ved Sharma wrote:
> a = 0;
> b = 0;
> for (i=0;i<10;i++) {
> print(a++);
> if (a==3) i = 1e99;
> print(b++);
> }
You can also use a separate boolean variable, lets call it "done" that can be used to prematurely terminate the loop.
You can use an "if" statement to to avoid the remainder of the loop being executed:
a = 0;
b = 0;
var done = false; // used to prematurely terminate loop
for (i=0;i<10 && !done;i++) {
print("a is " + a++);
if (a==3) {
done = true; // break
} else {
print("b is " + b++);
}
}
There are many variations on this theme that you can use.
Regards -- Michael Ellis