Can I have multiple conditions in the if statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can I have multiple conditions in the if statement

How many conditions can I have in the if statement

30th Jan 2023, 12:50 PM
Paxton Programer
9 Answers
+ 7
Yes using ( && or || ) And Or OR operator. Here's an example: if (n > 10 && n < 15 ) { // Do something } Here we have 2 conditions inside if statment, U can have infinite number of condition using AND or OR operator.
30th Jan 2023, 1:12 PM
Aakaanksha 💕 [TheBraveCoders]
Aakaanksha 💕 [TheBraveCoders] - avatar
+ 5
You can have multiple conditions in your if statement by combining it with any logical operator like and or not . For example: age = input() if(age >= 18 && age > 0 ||age <= 40 ){ print("Allowed") In this example there are total 3 conditions given in the if statement.
1st Feb 2023, 1:38 AM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 4
As many as you want
30th Jan 2023, 2:53 PM
A͢J
A͢J - avatar
+ 3
You have recently asked a very similar question in a thread that you have deleted. You can chain conditions with logical operators and you can chain and nest if-else-statements. You can have as many as you want. If you have a particular issue with a code, please link your code and describe what it is supposed to do.
30th Jan 2023, 1:35 PM
Lisa
Lisa - avatar
+ 2
Look up ternary you want to be more precise with your conditions.
30th Jan 2023, 2:42 PM
D_Stark
D_Stark - avatar
+ 1
You can use as much as you want..... by using &&(AND) operator and ||(OR) Operator for two or more conditions in same if statement
31st Jan 2023, 6:23 PM
Abhi_Raftaar
Abhi_Raftaar - avatar
+ 1
You can have as many condition as u want. Eg:- if(a>0 && a<50) { printf("Hello"); }
26th Mar 2024, 8:07 AM
Anuj
0
Lisa, I tried to find that question to find the way to code it, but I must have accidentally deleted it, as I could not find it
31st Jan 2023, 12:49 PM
Paxton Programer
0
Use iff for double condition
1st Feb 2023, 1:42 AM
Patrick ONeil
Patrick ONeil - avatar