Is this method viable for bool?


I’ve tested it and it works the same as:
(Response[0] == ‘y’) || (Response[0] ‘Y’);

Are these 2 methods exactly the same or is
(Response[0] == ‘y’) || (Response[0] ‘Y’); better?

EDIT: I just finished the next lecture and using (Response[0] == ‘y’ || ‘Y’) will make your program loop constantly when the loop code gets added (the code below is the finished code from lecture 23)

Because you need a full comparisono statement; this is equivalent to writing this

return 'Y' || Response[0] == 'y'

‘Y’ would just be implicitly comverted to a bool (all non-zero values are true) so that statement will always return true.

Ahhh, I see. Thanks for the clarification. :smiley:

Privacy & Terms