AL now supports the Continue statement

From runtime version 15, it is possible to use the continue keyword in loops to continue to the next iteration. (Please make sure that your “AL Language extension for Microsoft Dynamics 365 Business Central” is version 15.0 or above)

The continue statement allows skipping the remaining code in a loop’s current iteration and jumping directly into the next iteration. It simply means once the compiler hits the continue, it will skip executing the rest of the code in the loop, jump to the next iteration and start executing the code from the beginning.

IntelliSense still does not recognize the continue statement, and I hope Microsoft will fix it in the coming weeks.

Code:

    procedure DisplayDaysOfTheWeek(daysOfTheWeek: List of [Text])
    var
        weekDaysLbl: Label 'Weekdays are: %1', Comment = '%1 is the day of the week';
        dayOfTheWeek: Text;
    begin
        foreach dayOfTheWeek in daysOfTheWeek do begin
            if dayOfTheWeek in ['Saturday', 'Sunday'] then
                continue;

            Message(weekDaysLbl, dayOfTheWeek);
        end;
    end;

Result:

Weekdays are: Monday
Weekdays are: Tuesday
Weekdays are: Wednesday
Weekdays are: Thursday
Weekdays are: Friday

No more complex conditions to skip a loop!

Regards,
Tharanga Chandrasekara

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.