Statements¶
Statements are the building blocks of every EasyLang program.
A statement tells the interpreter what action to perform — such as assigning values, printing text, controlling program flow, or interacting with files.
This chapter explains every statement type supported by EasyLang, with clear examples based on the interpreter’s actual grammar.
Overview of All Statements¶
EasyLang supports the following categories of statements:
- Assignment Statements
- Print Statements
- Conditional Statements (if / else if / else)
- Loops (repeat while / repeat from)
- Function Definitions
- Function Calls
- Module Import (bring)
- File Handling Statements
- Return Statement
- Continue / Break
- Bare Expressions (evaluated for side-effects)
Each one is explained in detail below.
1. Assignment Statements¶
Assignments use natural English keywords:
we let <identifier> = <expression>
Examples:
we let x = 10
we let name = "GreenBugX"
we let total = price mul quantity
Reassignment simply reuses the same syntax:
we let x = x plus 1
Assignments always store the result of the right-hand expression in the variable.
2. Print Statements¶
Printing uses the phrase:
so print <expression>
Examples:
so print "Hello!"
so print x
so print x plus 10
The expression is evaluated first, then shown to the user.
3. Conditional Statements¶
Conditional logic uses a natural-style structure.
Basic Form¶
if <expression> then [
statements...
]
Example:
if x equals 10 then [
so print "Ten!"
]
Else¶
if x less 0 then [
so print "Negative"
] else [
so print "Positive or Zero"
]
Else If¶
else if <expression> then [
statements...
]
Complete example:
if score greater 90 then [
so print "A"
] else if score greater 75 then [
so print "B"
] else [
so print "C or below"
]
Blocks must always be enclosed in [ ].
4. Loops¶
EasyLang supports two loop forms: repeat-while and repeat-from.
4.1. Repeat While Loop¶
repeat while <expression>: do [
statements...
]
Example:
repeat while x less 10: do [
so print x
we let x = x plus 1
]
The loop runs as long as the condition is true.
4.2. Repeat From Loop (For Loop)¶
repeat from <var> = <start> to <end>: do [
statements...
]
Example:
repeat from i = 1 to 5: do [
so print i
]
The value of i increases by 1 every iteration.
5. Function Definitions¶
Functions allow you to group reusable logic.
Syntax
define <name>(arg1, arg2, ...): do [
statements...
]
Example:
define add(a, b): do [
return a plus b
]
Calling a function
so print add(3, 7)
Functions always return the result of the return expression.
6. Return Statement¶
Inside a function, you can return a value using:
return <expression>
Example:
define greet(name): do [
return "Hello, " plus name
]
If no return is used, the function returns null.
7. Module Import Statement¶
Modules allow you to load external EasyLang or Python code.
Import an EasyLang module:
bring "math.elangh" as math
Import a Python module:
bring math as m
so print m.sqrt(25)
Import an internal module:
bring strings as str
After importing, you use:
alias.function()
alias.property
Example:
bring "strings.elangh" as s
so print s.upper("hello")
8. File Handling Statements¶
EasyLang includes a simple but powerful file I/O system.
Open a File
open "path.txt" as f for read
open "out.txt" as file for write
open "log.txt" as l for append
Write a Line
writeline f with "Hello!"
Read a Line
readline f into line
Close a File
close f
Example:
open "out.txt" as f for write
writeline f with "EasyLang was here!"
close f
9. Continue and Break¶
These control loops.
Break
Stops the loop immediately:
break
Continue
Skips to the next iteration:
continue
Example:
repeat from i = 1 to 5: do [
if i equals 3 then [
continue
]
so print i
]
10. Expression Statements¶
Any expression that produces a value or performs a method call can also be a standalone statement.
Examples:
x plus 1 $ evaluated but unused
list.push(5) $ valid statement
print("ok") $ Python interop call
The interpreter evaluates the expression for its side-effect.
11. Summary Table¶
Here is a quick table of all statement types:
| Statement Type | Syntax Example |
|---|---|
| Assignment | we let x = 10 |
so print x |
|
| If | if cond then [...] |
| Else If / Else | else if ... |
| Repeat While | repeat while x less 10: do [...] |
| Repeat From | repeat from i = 1 to 5: do [...] |
| Function Define | define add(a, b): do [...] |
| Return | return value |
| Bring Modules | bring file as alias |
| File Open | open "file" as f for read |
| Write Line | writeline f with data |
| Read Line | readline f into var |
| Close File | close f |
| Continue / Break | continue, break |
| Expression Call | obj.method() |
Next Steps¶
Continue to Expressions to learn how expressions work in detail