InstallShield 2015 ยป InstallScript Language Reference
The for statement is designed to execute one or more statements a fixed number of times. It begins with the keyword for and an expression that specifies the number of times statements within the for structure are to be executed. The for structure ends with the keyword endfor.
Note: The for statement itself is not terminated with a semicolon; however, a semicolon is required after the endfor statement.
Using for...endfor
In the following example, the function MessageBox is called 10 times. On the first pass, iCount is set to 1. Because 1 is in the specified range (1 to 10), the message box is displayed. Then iCount is incremented by 1 and the for statement is resolved again. This time, iCount = 2 (still in the specified range) and the message box is displayed a second time.
When iCount is incremented after the tenth pass, its value becomes 11. Because this value is outside the specified range, the for statement ends.
for iCount = 1 to 10
MessageBox ("This appears ten times.", INFORMATION);
endfor;
Adjusting the Increment
The default increment in a for statement is one (1), but you can use the keyword step to adjust the increment. In the example below, step increases the value of iCount by 10 each time loop is executed. On the first pass, iCount = 10; on the second pass, iCount = 20; on the third pass, iCount = 30, and so on.
for iCount = 10 to 100 step 10
MessageBox ("This appears ten times.", INFORMATION);
endfor;
Counting Down from a Higher Number to a Lower Number
You can count down from a higher number to a lower number by using the keyword downto in place of the keyword to. In the following example, a message box is displayed three times. The first time the loop is entered, j is set to 20.
Because downto specifies that the controlling variable be decremented and step 5 sets a decrement of 5 per loop, j is equal to 15 the second time the loop is entered. The third time, j is equal to 10.
for j = 20 downto 10 step 5
MessageBox ("This appears three times.", INFORMATION);
endfor;
Note: You cannot define a label within a for statement.
See Also
InstallShield 2015 Help LibraryJune 2015 |
Copyright Information | Contact Us |