In the 1 month experience I've had with any programming language, I've assumed that switch
case
conditions would accept anything in the parenthesis as a boolean checking thingamajig, ie these:
|| && < >
Know what I mean?
something like
char someChar = 'w'; switch (someChar) { case ('W' ||'w'): System.out.println ("W or w"); }
Sadly, doesn't seem to work that way. I can't have boolean checking in switch case.
Is there a way around it?
By the way, terribly sorry if I'm sounding confusing. I don't quite know the names for everything in this language yet :X
Any answers appreciated
Case statement controls the different sets of a statement based upon different conditions. It contains WHEN, THEN & ELSE statements to execute the different results with different comparison operators like =, >, >=, <, <= so on. Case executes through the conditions and returns a result when the condition is true.
Syntax. SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]... AND [conditionN]; You can combine N number of conditions using the AND operator.
The SQL AND condition and OR condition can be combined to test for multiple conditions in a SELECT, INSERT, UPDATE, or DELETE statement. When combining these conditions, it is important to use parentheses so that the database knows what order to evaluate each condition.
You can achieve an OR for cases like this:
switch (someChsr) { case 'w': case 'W': // some code for 'w' or 'W' break; case 'x': // etc }
Cases are like a "goto" and multiple gotos can share the same line to start execution.
You can do -
switch(c) { case 'W': case 'w': //your code which will satisfy both cases break; // .... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With