Trusted answers to developer questions

What is the loop....until statement in Euphoria?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

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 variables
atom num, counter
counter = 0
num = 2
--start the loop
loop do
num += 2
counter += 1
print(1,num)
puts(1,"\n")
until counter = 5
--loop stops
end loop

Explanation

  • 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

euphoria
functions
Did you find this helpful?