How many levels of nesting are there in this design?

X is an integer test score between 0 and 100.

input X

if (0 <= X and X < 49)
output "you fail"

else if (50 <= X and X < 70)
output "you did OK"

else if (70 <= X and X < 85)
output "you did well"

else if (85 <= X and X < 100)
output "you did great"

endif
output "how did you do?"

3
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by Rashakil Fol

There are no nested if statements there, you could rewrite it to use nesting thus

if (0 <= X and X < 49) then
output "you fail"
else
if (50 <= X and X < 70)
output "you did OK"
else
if (70 <= X and X < 85)
output "you did well"
else
if (85 <= X and X < 100)
output "you did great"
end if
end if
end if
end if
output "how did you do?"

so the "end if" statement at the end of the code is not a nesting level?

depends on your definition, I tend to go with no . In this case depending on wether you count the if it's 0 or 1

Depending on your definition of "levels of nesting", you've got 0, 1, 2, 4, 5, or 8.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.