+ 1

How do you put more than one condition inside an if statement?

How do you put more than one condition inside an if statement?

26th Dec 2017, 9:51 AM
S-J
S-J - avatar
5 odpowiedzi
+ 16
u can use && , || //or u can use nested if statements ... but it would be better to make it in one statement only by use these logical operation given above 😃 example ::: if (a>10) { if (b>20){ System.out.println("yeah"); } } is same as ::: if (a>10 && b>20) System.out.println("yeah"); //we have reduced nested statement to a single if statement 😃 //hope it helps☺☺
26th Dec 2017, 10:35 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
by using && and ||
26th Dec 2017, 11:13 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
wait, so you use the && to add more functions? like if (a = 3 && y = 8) ?
26th Dec 2017, 9:59 AM
S-J
S-J - avatar
+ 1
First, you should specify language you're asking about. Because I'm a hideous stalker, I know it's c++. Use && for statements that both need to be true and || for statements of which at least 1 needs to be true. Example: if(x >10 && x < 20) x must be higher than 10 AND lower than 20 if(x <10 || x > 20) x must be lower than 10 OR higher than 20
26th Dec 2017, 10:01 AM
BlazingMagpie
BlazingMagpie - avatar
+ 1
you can do this also by nesting if statements like if(condition){ if(condition_true){ statement ---- } else{ statement----- } else{ statement to be executed---- }
26th Dec 2017, 6:11 PM
Saurav Kumawat
Saurav Kumawat - avatar