The repeat forever instruction is used to reexecute a set of instructions infinitely. The only programmatic way to terminate the loop is by exiting it with the exit repeat instruction.
Table 8.16. repeat forever syntax
| Production | Syntax | Links |
|---|---|---|
repeat_forever_instruction |
| the section called “repeat forever instruction” |
repeat_tail | ( "counter" ":" variable_id ) ? ( "id" ":" identifier ) ? | the section called “repeat tail” |
Example 8.19. repeat forever example 1
// display numbers from 1 to 10
repeat forever counter: i
console.message (i.to_string )
if i =v 10 then
exit repeat
end if
endExample 8.20. repeat forever example 2
service instruction_examples
command repeat_forever_example_2
script
// ask user to type a string composed of 3 characters
var string user_input // declare variable to hold result
repeat forever
v_user_input = se_console.co_ask_string ( "Please enter 3 characters:" ) // ask user to enter a string on the system console
if v_user_input.a_item_count =v 3 then // check if exactly 3 characters have been entered
exit repeat // if ok: exit the loop
else
se_console.co_message ( "Input error! Please try again!" ) // if not ok: display error message and restart again
end if
end repeat
se_console.co_message ( "You typed: " & user_input ) // display result
end script
end command
end service