...

Chaining else if Statements

You're not limited to just one else if. You can chain as many else if statements as you need to model complex decision-making.

When you have multiple else if statements, the computer checks each condition in order from top to bottom. As soon as it finds a condition that's true, it runs that block and skips all the remaining conditions.

Example: Calculating Grades

The code sample implements a grading system with five different grades. Try different scores to see how the program assigns grades: A+ (97+), A (90+), B (80+), C (70+), or D (below 70).

Loading...

Output (Console)