V_fiterror and nested logic

So I figured this out last night, but I have no idea why it works the way it does..

this gives me an iterative bug which wipes out all my fits after the first one fails

function omfgwhereisthedamnbug()

variable V_fiterror
for (i = 0; i < num; i+=1)

curvefit imageA

if (V_fiterror == 0)

.    curvefit imageB

..       if (V_fiterror ==0)
...        do some good stuff
..       else
...        kill this row in all my waves
...        i -=1
...        num -= 1
..       endif

else
.    kill this row in all my waves
.    i -=1
.    num -=1
endif
endfor
end



putting the line "v_fiterror = 0" immediately before both curvefits fixes the issue. Why? I figured that curvefit generates a new V_fiterror after each call, similiar to V_max etc.. with wavestats, but I guess not?

Edit: ok I can see from the helpfile that V_fiterror is input/output. I missed that last night somehow... But this changes my question to why would you need a special variable to tell a curvefit that it is going to fail before it even attempts the fit? Isn't that something you could do yourself like "if checkA fails, don't fit"?