❔ Issue with Creating a looping system for and entire program
So I made this block of code in order to loop my entire program and my issue is if theres a valid input by the user it fails to go through the first if else check and outputs the invalid input Text. I wonder what im doing wrong here.
22 Replies
Let's see how the boolean logic for input
Y
works outLook at your if. Read it out loud.
a || b && c || d
with a
being false
and everything else being true
false || true && true || true
true && true
true
I would also highly recommend sticking the asking for yes/no in a reusable method. Will make your main code more readable
can you elaborate on that please?
Something like
so I should create a method for looping the program instead of having it setup in main
Well the loop itself still goes on Main
No, you should create a method that asks the user if it should continue or not
Here is one I use
Although I could say that can wait
Learning how boolean logic works is a much more fundamental thing
true
because lets read it out
Introducing methods, switches, pattern matching, all that jazz before booleans is backwards
"if userResponse is not lower case y OR userResponse is not upper case Y..."
I did a course where boolean logic was taught so I do understand it to a certain extent but I completly forgot about it till now
Well, try to rewrite your statement then
In a way that makes sense, boolean logic-wise
Use a truth table if need be
yeah remember order of operations, and that each condition is evaluated individually.
ie, the second comparison doesnt know what the first one checked
so
(a != 'Y' || a != 'y')
will always be true. There are no values for a
where its ever falseah ok
thanks for the help guys
$close
Use the /close command to mark a forum thread as answered
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.