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 "your grade is" X
output "you did OK"

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

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

endif
output "how did you do?"

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 "your grade is" X
output "you did OK"
else
if (70 <= X and X < 85)
output "your grade is" X
output "you did well"
else
if (85 <= X and X < 100)
output "your grade is" X
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.