DEV Community

Cover image for Conditional Statements 2
EzeanaMichael
EzeanaMichael

Posted on • Edited on

2

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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay