Break statement not breaking, where to look for info?

Hi all,

After a long break, I've once again found myself writing max scripts. I've more or less finished my script, except for this one weird thing.

I have two nested loops, for-i and for-j. I want to break out of for-j when a specific condition is met, iterate through the rest of for-i, and then have the loop continue at i+1 as normal.

Should be simple, right?

However, it seems the BREAK statement doesn't work!

for j = value to bones_total_nr do
(
	if (another_value == 0) do
	(
		print("found a zero");
		break;
		print("it didn't break");
	)
)

This prints out:

"found a zero"
"it didn't break"

Break should break out of the for-j loop, but it doesn't. Am I misunderstanding something? Where could I find more information about this?

Thanks for your time

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Endoperez's picture

Solution

Thanks barigazy, I'm now using for-while!

I was using this resource:
http://www.scriptspot.com/bobo/mel2mxs/loops.htm

and relied on it too much without double-checking the information elsewhere. In this case, I mistakenly thought the Maya section also applied to the 3DS Max.

It seems like the MaxScript command for breaking out of loops is called exit;, not break; and while reading on for-while loops I also found out that the exit command is quite slow.

barigazy's picture

...

It's better to use for-loop this way

for j = value to bones_total_nr while (another_value != 0) do (print "Zero not found...jet :)")

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.