...

/

The else and else if Statement

The else and else if Statement

Let’s learn to refine conditional statements using else and else if in Dart.

Overview

Imagine you’re playing a game of basketball. When the game ends, to decide who won, the referee counts the total points made by each team. If team A made a greater number of points, they would be declared the winner, else Team B would be declared the winner.

Do you see how we have two different actions depending on the outcome?

If we want to write some code for the above scenario, the first thing that comes to mind is the if statement. But the if statement won’t be able to do the job on its own because it only caters to one condition and one outcome. Our scenario has two ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy