If..else..if ….else statement:-
else_if Statement में अगर if की Condition true होती है तो if का statement execute होता है। अगर if का condition false होता है तो वो अगले condition पर जाकर check करता है अगर वो condition true होता है तो वो उसका statement execute करता है। अगर कोई भी condition true नहीं होती तो वो else का statement execute करता है।
Syntax:- if (condition1)
{
Line of code to be executed if condition 1is true
}
else if (condition 2)
{
Line of code to be executed if condition 2 is true
}
else
{
Lines of code to be executed if condition 1 is false and condition 2 is false
}
Question:- 1. Wap to check positive, negative number or Zero number.
2. Wap to find weekday to given number (1 to 7)
3. Wap to find month name to given number (1 to 12)
If..else..if ….else statement:-
In else_if statement, if the if condition is true then the if statement is executed. If the condition of if is false then it checks the next condition and if that condition is true then it executes its statement. If any condition is not true then it executes the else statement.
Syntax:- if (condition1)
{
Line of code to be executed if condition 1is true
}
else if (condition 2)
{
Line of code to be executed if condition 2 is true
}
else
{
Lines of code to be executed if condition 1 is false and condition 2 is false
}
Question:- 1. Wap to check positive, negative number or Zero number.
2. Wap to find weekday to given number (1 to 7)
3. Wap to find month name to given number (1 to 12)