mini statements


The following kinds of statements are provided. You are free to have one statement per line, many statements per line, or many lines per statement. Euphoria does not use semicolons.

One abbreviation is available. For example, ? 2+2 is short for print(1, 2+2).

Assignment Statement:

Assign a value to a variable, subscripted variable, or sliced variable, for example

x[2][4][3..5] = {9, 8, "Hello"} 

if Statement:

An example of the most general form of if statement is:

if char = 'a' then 
    x = 1 
elsif char = 'b' then 
    x = 2 
    y = 0 
elsif char = 'c' then 
    x = 3 
    x = -1 
end if 

while Statement:

An example of a while statement is:

while x > 0 do 
    a = a * 2 
    x = x - 1 
end while 

for Statement:

A for statement sets up a loop with a controlling loop variable that runs from an initial value up or down to some final value, for example.

for i = 10 to 20 do 
    for j = 15 to 1 by -2 do 
		? {i, j} 
    end for 
end for 

The loop variable is declared automatically.

procedure Statement:

procedure foo( <parameter list> ) 
    -- subroutine statements to be executed 
end procedure 

function Statement:

function fum( <parameter list> ) 
    -- subroutine statements to be executed 
    return x  -- a return value is required 
end function 

The return value may be ignored.

type Statement:

type fum( object x ) 
    -- subroutine statements 
    return i -- either false (0) or 1 (true) 
end type 


Call a subroutine, passing arguments by value. For example

foo(x, y, z+2) 

A subroutine can call itself.

return Statement:

A return statement returns from a subroutine. If the subroutine is a function or type then a value must also be returned. for example.

return {50, "FRED", {}} 

exit Statement:

An exit statement exits from a while loop or for loop, for example

while 1 do 
    line = gets(0) 
    if atom(line) then 
		exit   -- end of file 
	 end if 
    buffer = append(buffer, line) 
end while 


Quick Links

User menu

Not signed in.

Misc Menu