If and while always evaluate the whole expression
-
Yes, excuse me, yet another if post. Consider it as a note, and correct my observation if you know better, please.
a = [] if (len(a) > 0) and (a[0] == 1) then // do something endif
I wanted to use the while loop like this, because I need to check something inside the array to decide if the loop should go on
a = [] i = 0 while (i < len(a)) and (a[i] == "test") loop // do something i += 1 repeat
workaround:
a = [] i = 0 while (i < len(a)) loop if (a[i] != "test") then break endif // do something i += 1 endif
Appendix 03/26/2020:
The first two code samples throw an out of bound exception. Thank you @PB____ for linking to the first post about this, I searched for if-then-else posts, so I was not able to find it. So, @Spacemario came to the same workaround. -
This definitely shouldn't happen and is a bug, Ill report it to the team 👍
-
A similar report was also mentioned in: https://fuzearena.com/forum/topic/644/logical-and-or-do-not-short-circuit
Also
and
andor
cast the result to a boolean value, for example(2 and 3) == 1
. I would expect(2 and 3) == 3
and(2 or 3) == 2
, but I do think beginning programmers might expectand
andor
to behave the way they are implemented now.Maybe it's an idea to add additional operators:
&&
and||
to implement short circuiting, without casting the type?Anyway, that's my opinion on it, do with it as you please...
-
I don’t even understand what your report is saying. But it’s ok because Mike seems to so maybe I missed something.
It’s already been stated before that Fuze does not perform short circuiting like some languages do.
As far as I can see, none of your loops will iterate at all. Or is that the point? That the last one does maybe?
-
They way I read it, the reasoning is that Fuze will throw an error because it does not perform short circuiting:
even though
a
is an empty array here, the expression(i < len(a)) and (a[i] == "test")
will try to evaluate bothi < len(a)
anda[i] == "test"
. So the first check does not 'protect' the second one. It will try to evaluatea[0] == "test"
anyway, even thougha
does not contain any elements.That's why I linked to the earlier short circuiting post.
-
I've not seen the other thread before so I can't say why I know that Fuze doesn't short-circuit, but it's not news to me. So yeah, it doesn't surprise me that
a[i] == "test"
errors, because Fuze doesn't short-circuit. I wouldn't have know that it evaluates right to left though so that's useful if true. -
Just checked, it does operate right to left (for both
or
andand
), but it will always evaluate both sides regardless.