If is a conditional statement , with which you may take one or more test conditions. There are 3 types
- If statement
- If-else statement
- If else-if ladder
- nested if-else
only if statement has only one condition ,if the condition fails it skips to next statement.
if -else is used for both true and false for a condition.
here, if the condition is true it executers statement1 and skips statement2.if the condition is false it executes statement2 and skips satement1. using else part is not mandatory,lets see one example
here, in this example ,the condition is ,the age of the person should be either 18 or more to enter the website. That means if the test expression given (a>=18) is true,it displays first message”you are allowed to enter this website” ,it it is false ,then the second message is displayed “you are not allowed to enter this website”.
3. If else-if ladder Statement
if else-if statement is used to work on multiple conditions .if the respective conditions are true then their statements are executed ,if they are false it skips to next condition
writing if-else in another if-else is called nested if-else
until the condition 1 is true condition2 executes again and again ,when it is false else will be executed