A for expression is particularly well-suited to looping situations in which unconditional repetition is needed. Conversely, situations in which conditional repetition is needed are often best dealt with using a while expression.In the upto variant, the value of the loop variable will iterate from the start expression to the end expression in step expression increments. If you omit the step expression, the step increment defaults to 1.In the downto variant, the value of the loop variable iterates from the start expression to the end expression in step expression decrements. If the step expression is omitted, the step decrements defaults to -1.Iterations of the loop are controlled by the end expression value. Before each iteration, the end expression is evaluated and compared to the loop variable. If the result is true (1), the expression list is evaluated. After each evaluation, the step expression is evaluated and added to the loop variable.Before each iteration, the end expression is evaluated and compared to the loop variable. In addition, after each evaluation of the do condition, the step expression is evaluated and added to the loop variable.A for loop terminates when the start expression has surpassed the end expression. The start expression can surpass the end expression in either an upwards direction, if you use upto, or in a downward direction, if you use downto.
for variable = start expression
Note: The start, end, and step expressions must all be simple expressions. The result of the list of expressions associated with the do condition.In the following example, the values of the elements are added to a drop-down list from an XML file using the addItem method for all of the XML elements listed under list1: