How to do multiple If statements with one else | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
- 1

How to do multiple If statements with one else

i need help on understanding how to do multiple if with one else .. so it would be like if all the above dont meet the condition execute else and thank you for your time

11th Dec 2016, 1:10 PM
Afosh sharaf
Afosh sharaf - avatar
7 Respuestas
+ 2
If you have more than one condition, you can add other condition with else if. So, if first condition false and second condition is true, then the second condition will be run.
11th Dec 2016, 1:13 PM
Biobii
Biobii - avatar
+ 1
If condition1 {} If condition2 {} . . Else {} Good enough?
11th Dec 2016, 1:41 PM
Unforgiven
Unforgiven - avatar
0
u.mean else if if() .... else if() .... .... .... .... else .....
11th Dec 2016, 1:43 PM
manish rawat
manish rawat - avatar
0
@afosh the way i weote them is optimised one if any one of statement of if else ladder is sarisfied then compiler goes after else block and hence saves time. if i use only if , if and no else every condition would be checked uselessly.
11th Dec 2016, 6:52 PM
manish rawat
manish rawat - avatar
0
the way i did😃 using if(condition 1) {..... } else if(condition 2) {..... } else if(condition 3) {..... } else
11th Dec 2016, 7:21 PM
manish rawat
manish rawat - avatar
- 1
but what if i have more than 5 conditions and i cant use switch with strings so i have to use if statements so to be clear i have more than 5 conditions, how should i do them ? @manish i mean it like this if 1 if 2 if 3 if 4 if 5 if non of the above meets the condition do else. if there is a better way to that i would be grateful
11th Dec 2016, 1:52 PM
Afosh sharaf
Afosh sharaf - avatar
- 1
yesss how could i do that
11th Dec 2016, 7:19 PM
Afosh sharaf
Afosh sharaf - avatar