Comment on if statement == false

<- View Parent
nickwitha_k@lemmy.sdf.org ⁨2⁩ ⁨weeks⁩ ago

I’m pretty sure that funky() would always return 0, as defined. I’ll pseudocide that up:

funky takes no args, returns int {
  a is assigned the value 0
  b is assigned the value 1

  test if a is equal to 1, if it is {
    b is assigned the value 1
  }

  return a
}

The if in your function can never be reached, without some weird manipulation of the value of a that breaks variable scoping in most syntaxes.

I think that I see your logic but it is syntactically incorrect:

        b=1
    }

In most syntaxes, this is a conditional execution and value assignment. That is, the code in curly braces only gets executed, if the conditional evaluates as true. If the conditional evaluates as true, the code is executed, assigning the value 1 to the variable b.

It does NOT imply that the assignment of the value 1 to the variable b is a conditional requiring the assignment of the value 1 to the variable b.

Remember: = in most programming is NOT an equality symbol but a value-assigment symbol. It would be nice if people creating the initial syntaxes used something else that is harder to confuse but they didn’t.

source
Sort:hotnewtop