End endless for loop


So I’ve accidentally created a endless for loop/print statement and I can’t seem to figure out how to stop it. Normally I’d just create a listen statement or just press esc… Any suggestions?


Post the code. Hard to help without seeing it.


nothing in peticular… just a for loop within a for loop. and if I havn’t done it right, they keep printing out… over and over and over… ect…

Meaning, the output I created will loop for a long time before completeing because of bad codeing on my part. The problem is, the only way I’ve found to stop it, is to force quit maya.


Again, without seeing it it’s hard to pinpoint your problem. However, you need a condition in your loop to test if something is true or not to break out of the loop. Just step through it in your head and try to follow the logic.


I don’t think he’s asking for help on figuring out the source of the infinite loop. Rather he’s asking if there’s a way to interrupt an infinite loop in Maya. I can’t say that I know of any off the top of my head, other than to quit Maya forcefully (eg. end the process).


Bryan Ewert has a script to do just this. I have never tested it, but try this link out.



What keliun said. I’m not trying to fix the script. I’m trying to figure out how to terminate it, if it get’s stuck in an endless loop.

Thanks mohavland… I’ll give that a shot. Though it would have been nicer if maya built in something like… the use of the escape key


I think I’m in an endless loop :banghead:.

Why would you program in the possiblity of an endless loop but then want user intervention to terminate it? Makes no sense. If “this happens”, terminate loop, “else” continue to loop.


I wouldn’t program in an endless loop. I would happen on accident while I’m writing code for something. Sometimes I write a bad for() loop and maya gets stuck looping on itself. In that case I would want a way of killing the script without having to end the maya task. I want a way out if I mess up while writing my code. For instnace, I was making a mirror cluster weights script yesterday, and maya was listing out all the verticies for me. Well I had accidentally mess up the script and it was printing all the verticies for every x value for every vertex on the object I was working on. That’s 4000 verts times 4000 xvalues times 4000 verts.

print statements…

Now, I don’t want to wait for maya to print out that many. And it certianly wasn’t my intention, but due to sloppy codeing on my part, that is what I had to deal with. So because of this, I want a way to cancel for loops until I’m better at writing code


Sorry, but that is the totally wrong way of learning to code. Putting in code to help with sloppy coding is sure fire for disaster.


My friend who is a computer sci major and an ex-programmer for a TeraData would have an escape key or method for when the code he was writing locks up. Not many people can write a script perfectly the first time, and since I am just learning MEL for the first time (before that I knew javascript/actionscript) I am bound to make mistakes. So it is only proper for me to want a way to abort my code. In fact it makes a lot of sense for me to want a way to abort my code when I mess up, since I am learning and am bound to make more mistakes than someone who knows how to code.

If you have suggestions on how to write code perfectly the first time, I would love to hear it. However please do not critize me for doing things my self taught way. Thank you


Sorry, no offense intended. Having wirtten C++, VB and perl scripts and programs, I’ve never written apps perfect the first time around for sure.

One thing you could add to your code is a condition test like this

for($i=0; $i < $hugeNumber;$i++)
if($i == 64000000)
print $i;

This will break out of the loop if your counter gets too high.

This is a bit old but is the only thing I know that will do what you want. I’ve emailed this guy ahile back and was nice enough to send the source code before. You could do the same but would need to be re-compiled to the version of Maya your using. It did come handy when running a batch file and I needed to escape out of it.


If you run into an endless loop situation and you need help with stepping through I’d love to help.


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.