How to do that | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

How to do that

I want to compare something like char or string with another for example the operators can I abbreviate this expression if (op=='+'||op=='-'||op=='*'||op=='/'){do something} to be like if(op=x){do something}

24th Sep 2018, 10:21 AM
ABADA S
ABADA S - avatar
4 Answers
+ 3
the point is that I want to abbreviate like char a= 'a'||'b'||'c'; if(op==a);
24th Sep 2018, 7:04 PM
ABADA S
ABADA S - avatar
+ 2
maybe its better to use the switch? if(po=='+'){ do ... } else if (po=='-'){ do ... } else if (po='*'){ do ... } else if (po=='/'){ do ... }
24th Sep 2018, 10:51 AM
Daniel (kabura)
Daniel (kabura) - avatar
+ 1
Do you mean that if one condition is true, do something? if (op = 'a' || op = 'b' || op = 'c') { do... }
24th Sep 2018, 7:58 PM
Daniel (kabura)
Daniel (kabura) - avatar
24th Sep 2018, 8:13 PM
Daniel (kabura)
Daniel (kabura) - avatar