

Task

Demonstrate a   for-loop   where the step-value is greater than one.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


%% Implemented by Arjun Sunel
%% for_loop/4 by Bengt Kleberg.
-module(loop_step).
-export([main/0, for_loop/1, for_loop/4]).
 
 % This Erlang code for "For Loop" is equivalent to: " for (i=start;  i<end ; i=i+2){ printf("* ");} " in C language. 
 
main() ->
	for_loop(1).    
 
 for_loop( N ) ->
	for_loop( N, 4, 2, fun() -> io:fwrite("* ") end ).
 
for_loop( I, End, Step, Do ) when N < End ->
    Do(),
    for_loop( I+Step, End, Step, Do );
for_loop( _I, _End, _Step, _Do ) -> ok.
 