Much like we discussed in Flowcharts, in pseduocode, we can also nest our conditions. That means that within the body of one true statement, or the else, false statement, we can nest a whole new decision.
A simple case is where we want to see if two things are both true, and we don’t know about Boolean operations yet. So, for example, we might want to test to see if you are over 16 years old, and thus old enough to drive. However, you also need a driver’s license to drive. So you check that in a second, nested condition, never asking, if person is under 16, because it isn’t relevant to them.
age = 18
hasLicense = true
if age >= 16 then
if hasLicense is true then
print "You are old enough to drive, and you have a license. You can drive."
end if age >= 16
end if hasLicense is true
Notice, in this case, I wrote end, for the if statement, but I also specified for which if statement. This way it’s abundantly clear, which it isn’t especially if you have multiple nested statements, and/or large blocks of code within the statement.
Also, you don’t have to only have the nested condition, you have have additional statements.
age = 18
hasLicense = true
if age >= 16 then
print "Excellent, you are old enough to drive."
if hasLicense = true then
print "You have a license. You can drive."
end
Nested conditions are nice, because you can write else clauses for each.
age = 18
hasLicense = true
if age >= 16 then
print "Excellent, you are old enough to drive."
if hasLicense = true then
print "You have a license. You can drive."
else
print "You must have a license to drive."
else
print "You must be 16 or older to have your operator's permit."
end
Nested Conditions in Pseudocode was originally found on Access 2 Learn