A way to fix loops so they can't go infinite is to make three types of loops… counting loops, list loops and conditional loops.
Counting loops would have a format as such
````
for LABEL VAR START STOP STEP
...
[exitfor LABEL]
...
endfor LABEL
````
where…
* LABEL = the name of the for loop to allow for nested loops
* VAR = the loop variable name, references as $VAR in the loop
* START = initial value (can be a numerical variable or ifcheck)
* STOP = final value (similar to START)
* STEP = a non zero step (similar to START, a ZERO value should do the loop for START only then exit)
* exitfor LABEL = exits the loop execution for that loop (basically, skips to the ENDFOR LABEL)
A list loop would iterate through a list expression (such as mob contents, room objects, online players, etc)
````
list LABEL VAR LIST
...
[exitlist LABEL]
...
endlist LABEL
````
where…
* LABEL = the name of the list loop to allow for nested loops
* VAR = the loop variable name, references as $VAR in the loop
* LIST = the list entity that provides the element to search. (this would utility the $( ) expression entity resolver, only accepting LISTs).
* exitlist LABEL = exits the loop execution for that loop (basically, skips to the ENDLIST LABEL)
This would take care to CHECK for infinite loops, by using a SEEN STAMP that is generated uniquely for that loop. When the current item looked at has a SEEN STAMP greater than or equal to the loop's generated stamp, it exits the loop. The reason for greater than or equal to is to account for the possibility that a nested loop within the current one manipulates said entity. Also, should the viewed entity be INVALID (such as a mob that was destructed), that forces a loop exit.
The last loop has the main potential for becoming infinite.
````
while LABEL IF-CHECK
[and IF-CHECK]
[or IF-CHECK]
...
[exitwhile LABEL]
...
endwhile LABEL
````
where…
* LABEL = the name of the while loop to allow for nested loops
* IF-CHECK = ordinary if-checks
* exitwhile LABEL = exits the loop execution for that loop (basically, skips to the ENDWHILE LABEL)
The test portion of the loop operates just like an IF statement, only a false value would look for the ENDWHILE LABEL line instead of ELSE or ENDIF.