+ 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?
6 Answers
+ 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âșâș
+ 5
by using && and ||
+ 1
wait, so you use the && to add more functions? like if (a = 3 && y = 8) ?
+ 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
+ 1
you can do this also by nesting if statements like
if(condition){
if(condition_true){
statement ----
}
else{
statement-----
}
else{
statement to be executed----
}