- 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
9 Answers
+ 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.
+ 1
If condition1 {}
If condition2 {}
.
.
Else {}
Good enough?
0
u.mean else if
if()
....
else if()
....
....
....
....
else
.....
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.
0
the way i didđ
using
if(condition 1)
{..... }
else if(condition 2)
{..... }
else if(condition 3)
{..... }
else
- 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
- 1
yesss how could i do that