Control flow - ValentunSergeev/Eiffel-Docs GitHub Wiki

Control flow

Content

Branching

One-branch if statement

if condition then
    -- do something
end

Two-branch if statement

if condition then
    -- do something
else
    -- do something 2
end

3+ branch if statement

if condition then
    -- do something
elseif condition2 then
    -- do something 2
else
   -- do something 3
end

Multibranch statement

inspect
    age -- could be a character or integer expression
when 0 then -- could be a character or integer value
    -- action
when 1 then
    -- another action
...
else
    -- default action
end

Loops

For loop (increment, including last value)

from i := 1
until i > 10
loop
    -- some actions, will be repeated 10 times
    i := i+1 
end

For loop (increment, excluding last value)

from i := 1
until i >= 10
loop
    -- some actions, will be repeated 9 times
    i := i+1
end

While loop

from
until not condition
loop
    -- some actions
end

Do while loop

from
    -- some actions
until not condition
loop
    -- some actions again
end

Across loop (goes through an iterable object)

across iterable as it loop
    -- some actions with current item (it.item)
end

Across int interval loop (similar to for loop)

across 1 |..| 10 as it loop
    -- some actions, will be repeated 10 times
end