Nan error causing code to fail

Hi, is there a way to break a for-loop when a particular quantity becomes equal to nan (not a number)? I.e. if during a loop I get quantity=nan, is there a way to break the loop? I tried inputting " for(quantity=nan) break; " into the loop, but this returns an error because freeFEM doesn’t recognise nan as an object. Is there some other way of doing it? Hopefully my question is clear!

I haven’t actually tried this but you may want to try
if (x*0 != 0) break

althought there could be an “isnan” function

it looks like there is an “isnan” function,

https://doc.freefem.org/references/functions.html

1 Like

Apologies, I accidentally deleted my reply, here it is again: Fantastic, this is exactly what I needed. Thanks Mike!