We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Infinite loop

David Collins
Advocate
I have just created yet another accidental infinite loop in GDL. I always feel this reflects well on my GDL skills, since this probably doesn't happen much to a novice.

So, as a buzillion roof beams spiral off into the vanishing point, I wonder if there's any way to stop them? Dropping out of a non-responsive ArchiCAD leaves me the autosave of the main file, but the GDL work in progress is just plain gone.
David Collins

Win10 64bit Intel i7 6700 3.40 Ghz, 32 Gb RAM, GeForce RTX 3070
AC 27.0 (4001 INT FULL)
7 REPLIES 7
Frank Beister
Moderator
AFAIK is there still no hotkey to stop it. No autosave for objects too.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Anonymous
Not applicable
It is always a good idea to save before running a script that has this potential. You might be able to get out of the loop with a command/ctrl + . (period/fullstop). Most infinite loops occur in REPEAT...UNTIL and WHILE...ENDWHILE conditions since it is easy for the terminal condition to never be met. I don't know if this is your situation, but a simple remedy is to put a simple counter inside the loop that will bail out after some large number of iterations. For example:
REPEAT
    ! Some useful code here
    count = count + 1
    IF count > 10^6 THEN 100
UNTIL pigs = "fly"
100: !Get out of loop free card
This example will count to one million before bailing out which may be excessive for your needs, but it should take well under 1000 seconds to execute (I recall testing the loops at around a millisecond once, but that was on a MUCH slower computer than anything we use now).

I have used a similar approach for loops where I couldn't predict the conditional value and it was easier to get out with the IF statement.
Frank Beister
Moderator
I most use FOR - NEXT loops, which do not loop endless so easy. Saving before trying is not every time the hint, because AC precompiles the code before saving and might run into the endlessness too. If I have not saved a long time ago and if I do not trust my code I set an END at the beginning of the master-script before saving and delete it afterwards for the test.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Anonymous
Not applicable
F. wrote:
I most use FOR - NEXT loops, which do not loop endless so easy. Saving before trying is not every time the hint, because AC precompiles the code before saving and might run into the endlessness too. If I have not saved a long time ago and if I do not trust my code I set an END at the beginning of the master-script before saving and delete it afterwards for the test.
Point well taken. I usually comment out the questionable code before saving, but that's a good idea about the END statement. I'll have to remember it.
Frank Beister
Moderator
I'll have to remember that.
Would be nice if I would every time too. 😉
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Anonymous
Not applicable
F. wrote:
I'll have to remember that.
Would be nice if I would every time too. 😉
I know what you mean
David Collins
Advocate
Thanks for the input, gentlemen

I figure if I ever need to defeat an evil super computer which threatens to kill my crew and steal my ship, this would be the way to go.
David Collins

Win10 64bit Intel i7 6700 3.40 Ghz, 32 Gb RAM, GeForce RTX 3070
AC 27.0 (4001 INT FULL)