Last Updated: June 7, 2026
This is a range lookup. A score is a single number, but grades come in bands, and the job is to find which band the score falls into. The bands do not overlap and together cover every possible score, so each input maps to exactly one grade.
The bands are ordered, which is why an else-if ladder fits. Once you know a score is not an A, you know it is below 90. Checking the highest band first and working downward means every comparison after the first needs a single threshold, because the upper bound of each band is already guaranteed by the branches that failed before it.
>= at each threshold.Test the thresholds 90, 80, 70, 60 in that order, and the first one the score clears determines the grade. A score of 83 fails the >= 90 test, then passes the >= 80 test, so it stops there as a B.
If you checked from the bottom up instead, you would write two-sided ranges like marks >= 80 && marks < 90, which is more code and more chances for an off-by-one mistake.
marks is at least 90, return "A".marks is at least 80, return "B".marks is at least 70, return "C".marks is at least 60, return "D"."F".Input:
The score is 72. The first test, 72 >= 90, is false, so it is not an A. The second test, 72 >= 80, is also false. The third test, 72 >= 70, is true, so the ladder stops here and returns "C". The lower branches for D and F never run.