Loops

repeat while instruction

Description

The repeat while instruction is used to repeat executing a set of instructions as long as a certain condition is fulfilled.

Syntax

Table 20.12. repeat while syntax

ProductionSyntaxLinks
repeat_while_instruction

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

remark: expression must be of type yes_no

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

Examples

Example 20.9. repeat while example 1

// display numbers from 1 to 10

var positive32 i = 1
repeat while i <= 10
   system.console.write_line ( i.to_string )
   i = i + 1
end

Example 20.10. repeat while example 2

service instruction_examples

   command repeat_while_example_2
      script
      
         // ask user to type a string composed of 3 characters

         var string user_input                                                           // declare variable to hold result

         var yes_no input_ok = no
         repeat while not v_input_ok                                                     // loop while input is not ok
            v_user_input = se_system.console.ask_string ( "Please enter 3 characters:" ) // ask user to enter a string on the system console
            v_input_ok = v_user_input.a_item_count =v 3                                  // check if exactly 3 characters have been entered
            if not v_input_ok then
               se_system.console.write_line ( "Input error! Please try again!" )         // if not ok: display error message and restart again
            end if
         end repeat

         se_system.console.write_line ( "You typed: " & user_input )                     // display result

      end script
   end command
   
end service