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 <Statement> |
Let’s take an example- Assign a value to the ARRAY variable according to the number of records as shown in fig-
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() begin end; local procedure HowToUseFORTOStatement(i: Integer; j: Integer) var ArrayText: array[10] of Text[250]; begin i := 1; j := 10; for i := 1 to j do begin ArrayText[i] := ‘A’ + format(i); end; end; } |