Examples: Using iterative statements

The three agents that follow all display the elements of the Categories field one at a time.

  1. This agent uses an @For loop. The first parameter initializes the variable n to 1 and executes once. The second parameter tests whether n is less than or equal to the number of elements in Categories. The third parameter increments n. The fourth parameter is a statement that executes as long as the test remains True.
    @For(n := 1;
    n <= @Elements(Categories);
    n := n + 1;
    @Prompt([Ok]; "Category " + @Text(n); Categories[n]))
  2. This agent uses an @While loop.
    n := 1;
    @While(n <= @Elements(Categories);
    @Prompt([Ok]; "Category " + @Text(n); Categories[n]);
    n := n + 1)
  3. This agent uses an @DoWhile loop.
    @If(@Elements(Categories) = 0; @Return(0); "");
    n := 1;
    @DoWhile(
    @Prompt([Ok]; "Category " + @Text(n); Categories[n]);
    n := n + 1;
    n <= @Elements(Categories))