조건문 및 루프 명령문
조건문은 프로그램 내에서
제어를 전송합니다. EGL은 다음과
같은 조건문을 제공합니다.
- case
- if, else
루프 명령문은
명령문 세트를 반복할 횟수를 판별하는 조건을
테스트합니다. 루프 내에 테스트된 초기 조건을 변경하는
항목이 있어야
합니다. EGL은 다음과 같은 루프 명령문을 제공합니다.
- for
- forEach
- while
또한 조건문과 루프 명령문 내에서 탐색에
사용되는
두 개의 EGL 명령문이 있습니다.
- continue
- exit
루프 명령문에
레이블을 지정하고 탐색 명령문에서 해당 레이블을 참조할 수
있습니다. 레이블은 다음 예제와 같이 콜론(:)으로 끝납니다.
OuterLoop:
while(moreFood())
meal string = getMeal();
while(meal!="")
course string = nextCourse(meal);
eatCourse(course);
if(indigestion())
exit OuterLoop;
end meal = remainingCourses(meal);
endend
외부 루프 명령문에 레이블을 지정할 수 없는
경우에는 코드가 더
복합적이어야 합니다. 다음 예제에서 추가된 명령문이 굵은체로
표시되어
있습니다.
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);
endend