Warcraft III resources & community, 2003–2006 · archived

Looping code

2 posts
#1

Looping code

I'm having a hard time getting long loops to run properly in my maps, and I have been unable to find any information about this phenomenon on the Internet.


// This will run without problems
function ex1 takes nothing returns nothing
local integer i = 0 
    loop
        set i = i + 1

        if i == 5 then
            call DoNothing()
        endif 

         exitwhen i == 2000
     endloop
endfunction

// This will also run without problems
function ex2 takes nothing returns nothing
local integer i = 0 
    loop
        set i = i + 1

       // if i == 5 then
       //     call DoNothing()
       // endif 

         exitwhen i == 20000
     endloop
endfunction

// This function will never finish
function ex3 takes nothing returns nothing
local integer i = 0 
    loop
        set i = i + 1

        if i == 5 then
            call DoNothing()
        endif 

         exitwhen i == 20000
     endloop
endfunction


My question is: Why does ex3 hang/crash/break when the code is obviously correct? (This also goes for various nested loops when the number of iterations is too high). Any help would be greatly appreciated.
#2
There is a limit on the number of statements that a thread may execute without a wait. Once that limit is reached the thread is cancelled.