How to use FOR-TO loop statement in Microsoft D365

Use FOR-TO loop statement in Microsoft D365:

Definition of “FOR-TO”:  Repeats the inner statement until a counter variable equals the maximum or minimum value specified.

Syntax: “FOR-TO” statement-

FOR <Control Variable> := <Start Number> TO <End Number> DO 

Let’s take an example- Assign a value to the ARRAY variable according to the number of records as shown in fig-

Assign value to ARRAY variable according to the number of records

In the above example-

Declare the array and assign values to each element using the “FOR LOOP” statement.

Calculate the length of the array using the ArrayLength function.

Assign a variable to store the length of the array.

According to the above example loop counting number is 10 because I = 1 and j = 10.

ArrayText stores values ArrayText[1] = A1,ArrayText[2] = A2…………….ArrayText[10] = A10.

Source Code:

codeunit 50001 “Custom Functions-01”
    trigger OnRun()
    local procedure HowToUseFORTOStatement(i: Integer; j: Integer)
        ArrayText: array[10] of Text[250];
        i := 1;
        j := 10;
        for i := 1 to j do begin
            ArrayText[i] := ‘A’ + format(i);

How to Find Base Application Object in BC D365
How to Design Tiles view in Pages in Business Central
How to create a New Instance in Dynamics 365 BC, Business Central
How To Import License File In Business Central D365 On-premises
Set Up Goods and Services Tax Posting– Microsoft Docs

Leave a Reply