BUG: Expression - if - unused statement is evaluated

coming from a text-based (c#) programming background sometimes grasshopper is quite hard for me to understand. Sometimes i feel so stupid:

in c#, the behaviour i want:

 if (x>1)
    {
      A = 1 / (x - 1); // statemtent 1 true
    }
    else
    {
      A = 0.5; // statement 2 false
    }

it is obvious, that if the condition is false, the statment 1 is not evaluated.
for x = 1, i will not get a “division by zero” error.

but in grasshopper inside a expresion component
if((x>1),(1/(x-1)),0.5)
will throw an exception “division by zero” for x=1
why ?
why is the statement in the “true” section evaluated - even if the condition is false?
what do i miss ?

statement_evaluated.gh (7.0 KB)

is there any (native) spaghetti-solution ?

thanks.

kind regards -tom

Try this: If(x>1, 1/(x-1),0.5)

thanks @emerson.porras for having a look at this and for your suggestion
… does not work either… the brackets have no effect.

i found a really ugly, unsatisfying way not get an error:
combine an expresion (output text) with evaluate (to do the logic)…
(but it feels like bricolage):

this work
if((x>1),(x-1)^-1,0.5)

dear @ThomasE - thanks. - i would call it work-arround.
0^-1 is implemented as positiv infinite
1/0 is division by zero exception…

so i think the statement is still evaluated. (but not causing a error)
;-(

Hi Tom,

Here’s another nasty little workaround that exploits the idea that it’s ok to corrupt the algorithm so it can evaluate safely, given that the altered evaluation won’t be output:

Let’s hope the If statement gets fixed so that this sort of horror isn’t necessary.

Regards
Jeremy

ok - so you agree on call it a bug ? already known in other topic ? tracked ?

Yes, I’d call it a bug - maybe you should tag the original post as such.

dear @DavidRutten can you please have a look at this topic ?
or pleas @pascal can you direct this topic to the right person - thanks. kind regards tom