Conditional statements transfer control
within a program. EGL offers the
following conditional statements:
Loop statements
test a condition to determine how many times to repeat
a set of statements. Something in the loop must change the initial
condition
tested. EGL offers the following loop statements:
In addition, there are two EGL statements that are used
for navigation
within conditional and loop statements:
You can label
loop statements, and refer to those labels in navigation
statements. Labels end with a colon (:), as in the following example:
OuterLoop:
while(moreFood())
meal string = getMeal();
while(meal!="")
course string = nextCourse(meal);
eatCourse(course);
if(indigestion())
exit OuterLoop;
end
meal = remainingCourses(meal);
end
end
If you were unable to label the outer loop statement,
your code would have
to be more complex. Added statements in the following example are
shown in
bold:
hasIndigestion boolean = false;
while(moreFood() && !hasIndigestion)
meal string = getMeal();
while(meal != "")
course string = nextCourse(meal);
eatCourse(course);
if(indigestion())
hasIndigestion = true;
exit while; // This exits only the nearest while loop
end
meal = remainingCourses(meal);
end
end