Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - for iteration start http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 for                 Iteration start
------------------------------------------------------------------------------
 Syntax
   for <variable> := <startvalue> to|downto <endvalue> [ step <increment> ]
      <code>
   next

 Arguments
    <variable> is an integer variable used as a loop counter.

    <startvalue> is the value of the loop counter when the loop
    starts.

    <endvalue> is the value of the loop counter when the loop
    is to be ended.

    <increment> is an integer value by which the loop counter variable
    is incremented every time the loop is executed.

    <code> is executable code within the loop construct.

 Description
   The for statement is an iterative construct with an integer
   counter built in.

   The for...to/next construct assigns a given starting value
   to a declared integer variable, and performs the instructions
   within the construct block, incrementing the variable each time until
   the integer is equal to its end value. If the starting integer
   value is greater than the upper integer value, the loop block
   will not be executed at all.

   The second form of the for/next construct uses the keyword downto instead
   of to, and decrements the counter variable with each iteration. The
   downto statement must not be used with an unsigned counter variable, when
   the lower limit value of the loop is zero (an infinite loop is the
   result). When counting down to zero, use a signed data type (int or
   long) as the loop control variable.

   If the step clause is included, the counter will be
   incremented/decremented by the value defined following the step
   option. If there is no step option included with the command, the
   default value of 1 or -1 will be used.

 Example
   #define EXAMPLE_STATEMEN
   #include example.hdr

   proc Test_for
   vardef
      int     n
      logical lRepeated
   enddef
   lRepeated := .f.
   for n := 1 to 9                    // main loop control statement
      ? n                             // initial processing
      if n == 5 .and. .not. lRepeated // intermediate condition 1
         ? "Repeat"
         lRepeated := .t.             // set a loop control variable
         loop                         // restart cycle
      endif
      if lRepeated                    // intermediate condition 2
         ? "Finish"
         exit                         // leave cycle
      endif
   next
   ?
   for n := -200 to -150 step 10      // increment loop counter by 10
      ? n
   next
   ?
   for n := 1000 downto 800 step 50   // decrement loop counter by 50
      ? n
   next
   endproc

   proc main
   Test_for()
   endproc

See Also: next

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson