What is the loop....until statement in Euphoria?
Introduction
Control statements or loops in programming are statements intended to make codes continue a particular iteration in a certain way based on the provided condition. The loop will be exited on the satisfaction of this condition. This is necessary when repetitive actions are to be performed in a program.
Looping in Euphoria comes in different structures. One such loop structure in the Euphoria language is the loop...until statement.
The loop...until statement
The loop...until statement will continue in a particular course of action until a particular condition is met.
General syntax
loop do
--code block to be executed
--set counter
until --condition is met
The loop makes sure the condition is met. At every iteration, the condition is checked, and the counter incremented. Whenever the condition evaluates as true, the loop is exited. If not, the iteration is repeated once more.
Code
--declare some variablesatom num, countercounter = 0num = 2--start the looploop donum += 2counter += 1print(1,num)puts(1,"\n")until counter = 5--loop stopsend loop
Explanation
-
Line 2:
numandcounterare declared as a variable of theatomdata type. -
Line 7: The loop statement starts on
line 6. -
Lines 8-11: These commands and the arithmetic expressions continue to execute and evaluate until the condition on set is
true. -
Line 12: After every iteration, the
numvariable’s value is increased and checked if it equals5as stated in theuntilcondition. Once this condition is evaluated as true, the loop terminates.