if...else Statements | SoloLearn: Learn to code for FREE!

+1

if...else Statements

Can we put two conditions in if statement.

9/15/2018 2:17:10 AM

kp kalia

6 Answers

New Answer

+5

yes, if(x == 3 && y == 7){}

+1

I will try Nested if Statements chapter. Hope to serve purpose.

+1

&& - AND (True if both values are true) || - OR (True if either of the values are true) != - logical not (understandable ) You can put as many conditions as you want in if statement.

+1

Absolutely! You just need to use conjunctions like and &&, or || . And conditions like equals ==, not equals !=, greater than >, less than < etc.

0

It is common for languages (Java and Python are among them) to evaluate the first argument of a logical AND and finish evaluation of the statement if the first argument is false . This is because: ... When Java evaluates the expression d = b && c;, it first checks whether b is true more details you go to this websitehttps://www.programiz.com/java-programming/if-else-statement

0

You can you have as many condition as you like not only one or two, also you have groups of conditions inside parenthesis as well like in the example bellow. you can use a single AND"&" and OR "|" or double AND"&&" and OR "||" operators. The difference is when you use a single simple the compiler will check all the conditions inside your if statement if you use the double ones (short cuts) it will stops once one of the conditions are meet which is more efficient and some times help you to avoid exception. int a = 1; int c = 10; if( (a != c && c < 20 && a > 2 ) || (c == 10) || (a==1 && c > 3) { //some nice code goes here. }