0

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?"

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

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?"

0

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

0

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

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.