# Nan error causing code to fail

**URL:** <https://community.freefem.org/t/nan-error-causing-code-to-fail/2623>\
**Category:** General Discussion\
**Created:** [July 26, 2023, 2:46pm UTC](https://community.freefem.org/t/nan-error-causing-code-to-fail/2623 "2023-07-26T14:46:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jna1g18](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jna1g18](https://community.freefem.org/u/jna1g18)\
**Post date:** [July 26, 2023, 2:46pm UTC](https://community.freefem.org/t/nan-error-causing-code-to-fail/2623/1 "2023-07-26T14:46:30Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [July 26, 2023, 3:03pm UTC](https://community.freefem.org/t/nan-error-causing-code-to-fail/2623/2 "2023-07-26T15:03:00Z")

</div>

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](https://doc.freefem.org/references/functions.html)

---

<div class="post-metadata">

**Author:** ![jna1g18](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@jna1g18](https://community.freefem.org/u/jna1g18)\
**Post date:** [July 26, 2023, 3:31pm UTC](https://community.freefem.org/t/nan-error-causing-code-to-fail/2623/4 "2023-07-26T15:31:59Z")

</div>

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