Solidity If Else – Else If Conditions
In this article, we’ll take a closer look at Solidity if else else if statements with examples. We’ll also discuss some best practices for using these statements and common pitfalls to avoid.
Solidity conditions are used to evaluate a particular statement and execute a specific action based on the outcome of the evaluation.
They are similar to conditional statements in other programming languages like if-else and else-if conditions.
During the process of writing a program, there might come a time when you need to choose one path out of a set of possible paths that you have been given.
In such cases, you will need to make use of conditional statements in your program in order to be able to make the correct decision and take the correct action.
In Solidity, conditions are used to execute specific actions based on the state of a smart contract.
Let’s take a look at solidity if statements.
Solidity if statement
Solidity uses the if statement to make decisions and execute statements based on conditions.
Syntax
if (expression) { //Block of code that runs if the corresponding condition is met }
Here is an example of evaluating a Solidity expression.
The statement(s) given are executed if the resulting value is true.
The statement would not be executed if the expression is false.
Conditions are usually based on comparison operators.
The following program shows if a given number is even or odd:
Example: 
The following programme evaluates if the user is capable of voting by comparing his/her age:
Example: 
Solidity If Else statement
Solidity if else condition allow statements to be executed in a more controlled manner.
Syntax
if (expression) { //Statements to be executed if the condition is met } else { //If condition is false, the following block of code is executed }
An evaluation of a Solidity expression is performed here.
Accordingly, the ‘if‘ block executes the given lines of code if the condition is met.
The else block executes the relevant statements if the expression is false.
The following program illustrates the working of if-else statements:
Example: 
The following program shows the voter_Age_Checking system using if-else statements:
Example: 
Solidity if-else if Statement
Solidity if…else if statement is an advanced form of the if…else conditions which allows Solidity to make a correct decision out of a set of conditions when it comes to making a decision.
Syntax
if (expression 1) { //Executes the block of code if the if condition is met } else if (expression 2) { //Displays the code if the corresponding condition is matched } else if (expression 3) { //Matches the condition in the expression and executes the code if condition is met } else { //If none of the condition is matched from the if , else if block the code in the else block is executed }
This code isn’t special in any way. Basically, it consists of a series of if statements, where each if is part of the previous statement’s else clause.
Depending on the true condition, statement(s) are executed; if no true condition is observed, then else blocks are executed.
Example: 
Example: 
Conclusion
Solidity If…else conditions are an essential aspect of programming in the Solidity language for Ethereum smart contracts. They allow developers to create reliable and secure contracts that can handle a range of different situations and ensure the proper execution of the contract code.
By understanding the different types of conditions available, developers can ensure that their smart contracts function as intended, providing a solid foundation for the creation of decentralized applications on the Ethereum network.