In JAVA, when we program and we want to test a set of condition, the if - else statement comes into play. An if - else statement is used to test conditions for a program. It can also be used for error - trapping.
- if statement
The if statement can stand on its own and else statement is optional. For if statement it will be executed only if the condition is met or is true. If it is false, then nothing happens.
- nested if statement
The nested if statement is a structure where there is a condition within another condition. If the first condition is met then it will proceed and if the 2nd condition fails, then nothing happens. The statement will only run if both conditions are true.
- if-else statement
The if statement will execute if the condition is met or is true and the else statement will execute if the condition fails.
- if - else - if statement
This statement is used when a program needs to check for multiple conditions.
Note that there can be only one if and else statement, but else if statement can have multiple occurrence.
I Hope this helps. Thanks for taking the time to read :)
You have a minor misspelling in the following sentence:
It should be occurrence instead of occurence.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit