Skip to content

Control Flow

In Seal, control flow is straightforward. It has off-side rule aka indentation rule for defining where blocks start and end like Python, CoffeeScript, ABC.

If-Else

if a > 0
    print("a is positive")
else if a < 0
    print("a is negative")
else
    print("a is zero")

You just use indentation to define blocks. No : unlike Python.

a = integer(read())

if a == 0 then print("zero")
else if a == 1
    print("it is one")
else if a == 2 then print("two")
else print("unknown")

Inline if-else blocks are written with then. You can mix them with the ones with blocks.

While

while true
    print("this will print forever")

While loop is straightforward as well.

while true do print("hello")

You can write inline while loop too with do keyword.

Seal-style loop

i = -1
max = 10
while ++i < max
    print(i) 

Instead of putting ++i at the end of the loop body, you can put the increment into the condition check itself, and compensate by assigning -1 to i before the loop begins. So it becomes kind of a "C-style for loop". If you'll let me, I want to call this "Seal-style loop".

For

for i in 10
    print(i) // from 0 to 10 (10 is excluded)

for c in "my string"
    print(c)

for x in [1, 2, 3, 4, 5]
    print(x)

Currently, for loop supports 3 types of iterables: integer, string and list.

sum = 0
for i in 10 do sum += i
print(sum)

Here is inline for loop as well.

Skip and Stop

for c in "Hello, World!"
    if c == "l" then skip
    if c == "r"
        stop

    print(c)

Output:

H
e
o
,

W
o

As you can tell, skip is for the traditional continue keyword, and stop is for break. I have used these keywords since the first version of Seal, and decided to keep them. Because why not?

Function

Functions are created with define keyword. They are defined either with indented block, or right after the keyword. Some examples:

define greet(name)
    print("Hello", name)

// after block ends, the function definition does too.

greet("Dear Seal Programmer") // "Hello Dear Seal Programmer

define square(x) x * x
// if an expression comes after definition in the same line,
// that is returned implicitly without `return` statement.

print(square(4)) // 16

Include

include "io"

Include statement requires string after it. Here are standard library names:

  • "math"

  • "io"

  • "system"

When you include a file, you get capital case named global variable as a convention.

include "math"
Math // global hashmap holding mathematical functions
include "io"
IO  // again, global hashmap holding IO-related functions
include "io"  //  does not load again

When include statement is executed, first, it looks for standard libraries. Then, local files. It can include both so, dll files or Seal scripts. It starts with shared object files, and then Seal files. It loads the file only once.