If….Else


This image has an empty alt attribute; its file name is image-9.png

Hi,  we will go through the Java conditional statements in this post.  

Java supports if and else statements to run code under certain condition(s) to execute if it is a true evaluation or to skip if it is a false evaluation. This is also called Java control flow statements. This makes sense, right? It basically allows smooth flow of java programs. Let’s explore more;

Java has four types of if statements.  Each of them is explained below with examples.

1- if statement : a block of code to be executed when specified conditions is  true 

Example:

2- if…else statement: a block of code to be executed when specified condition for if statement is false

Example:

3-if…else…if statement: if statement will be followed with else if statement.  Else if gives an other condition and will be executed when it is true

Example:

4-nested if…else…if statement: This allows to use if…else statements inside of other if…else statement

Example:

Leave a comment