repeat times instruction

Description

The repeat times instruction is used to execute a set of instructions a certain number of times.

Syntax

Table 20.15. repeat times syntax

ProductionSyntaxLinks
repeat_times_instruction

"repeat" expression "times" repeat_tail ?
   script_instruction *
"end" "repeat" ?

remark: expression must be of type positive32

the section called “repeat times instruction”
repeat_tail( "counter" ":" constant_id ) ? ( "id" ":" identifier ) ?the section called “repeat tail”

Examples

Example 20.17. repeat times example 1

// display numbers from 1 to 10

repeat 10 times counter: i
   system.console.write_line ( i.to_string )
end

Example 20.18. repeat times example 2

The code below will display the following on the system console:

This is round 1
This is round 2
This is round 3
This is the last round.
service instruction_examples

   command repeat_times_example_2
      script

         const positive32 number_of_repeats = 3
         repeat c_number_of_repeats times counter: repeat_counter
            se_system.console.write_line ( "This is round " & c_repeat_counter.co_to_string )
            if c_repeat_counter =v c_number_of_repeats then
               se_system.console.write_line ( "This is the last round." )
            end if
         end repeat

      end script
   end command
   
end service

See also