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.
loop...until
statementThe loop...until
statement will continue in a particular course of action until a particular condition is met.
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.
--declare some variablesatom num, countercounter = 0num = 2--start the looploop donum += 2counter += 1print(1,num)puts(1,"\n")until counter = 5--loop stopsend loop
Line 2: num
and counter
are declared as a variable of the atom
data 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 num
variable’s value is increased and checked if it equals 5
as stated in the until
condition. Once this condition is evaluated as true, the loop terminates.
RELATED TAGS
CONTRIBUTOR