Be the first to post for 'Booleans and comparisons'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

Just thought I would post my code thus far, I accidentally made an infinite loop and tried to rewrite it without referencing the learning material. So it’s basically the same but with simpler naming :wink: And I wanted to thank our instructors and the students I’ve dealt with so far. Not a bad experience to be found One question I had is for line 61, I was wondering if this would also work:

return (Response[0] == ‘y’ || ‘Y’

and if not why? I’m just assuming that the “or” command should work like that without any coding knowledge fyi. Thanks in advance to anyone that answers :slight_smile:

It willl compile (with the missing ‘)’ added) but you would get unexpected results. The reason being that the right hand side of the expression is independant of the left, so say we no longer care about comparing the element to ‘y’ and just remove it, now you would just have return 'Y' and it would always evaluate to true (non-zero values evaluate to true) since it’s not actually being compared to anything.

1 Like

So just to ensure that I understand, in this case it wouldn’t really cause a problem but if I were, say, looking for a negative to progress and I tried this method it would always default positive?

Response[0] == 'y' || 'Y' wil always be true. The two possible outcomes are true || true and false || true which will both evaluate to true.

1 Like

Okay cool, thanks again.

Privacy & Terms