Saturday, July 25, 2009

FOR,WHILE,REPEAT

C/AL Repetitive Statements
A repetitive statement is also known as a loop. The Different Loop statements are Given below.
1. FOR
2. WHILE
3. REPEAT

FOR
Repeats the inner statement until a counter variable equals the maximum or minimum value specified.
The Two Control Structures In FOR Statement are FOR TO and FOR DOWNTO.
The Syntax For The above control structures are given below.
FOR [Control Variable] := [Start Number] TO [End Number] DO
[Statement]
The data type of [Control Variable], [Start Number], and [End Number] must be Boolean, number, time, or date.
Use FOR statements when you want to execute code a specific number of times.
Use a control variable to control the number of times the code is executed. The control variable can be increased or decreased by one, depending on whether TO or DOWNTO is used.
When using a FOR TO loop, the [Statement] will not be executed if the [Start Number] is greater than the end value. Likewise, when using a FOR DOWNTO loop, the [Statement] will not be executed if the [Start Number] is less than the end value.
For Eg:
1. Consider a variable 'I' for Loop.
FOR I=1 To 5 DO
Statement 1;
2. The following example shows how to nest FOR statements.
FOR I := 1 TO 5 DO
FOR J := 1 TO 7 DO
A[I,J] := 23;

No comments: