Basic Calculator

Why it is necessary to put
else if(ch==‘x’ or ch==‘X’){
return 0;
}
as we have already mentioned in while(ch!=‘X’ or ch!=‘x’)
Why it doesn’t terminate directly when while condition is not true?

Hello @AK072672,

It is necessary to mention this condition inside the do-while because the do-while loop will execute the if-else statements at least once. So, if you remove this else if(ch==‘x’ or ch==‘X’) then, control will immediately move to the else part and would print “Invalid operation. Try again”

You can read more about this from the below link,

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.