DEV Community

Cover image for Conditional Statements 2
EzeanaMichael
EzeanaMichael

Posted on • Edited on

Conditional Statements 2

In the last lesson I discussed conditional statements using the if-else keywords, but what is you want to create a nested if statements so different variables can produce different results
You can then use the if...elif...else or as is can also be called nested if statement.
So rather then writing code like
Code:
Image description

Output:
Image description
Here's how to write it:
Code:

Image description

Output:
Image description

An example of a practical application of this is a code I wrote in the GPA calculator post.

Image description

Here it shows different outputs for different conditions fulfilled.
NOTE:You can also use boolean operations in and if else statement an example is

Image description

Image description

Hope you enjoyed this lesson, thanks for reading, like, share, comment, next post will be available next week.

Top comments (0)