Bloa Documentation

Complete guide to the Bloa programming language

Syntax

Bloa uses a clean, readable syntax inspired by modern programming languages. Statements end with newlines, and blocks are enclosed in curly braces {}.

# Comments start with hash

say("Hello, World!") # Print to console

Variables

Variables are dynamically typed and declared using the assignment operator =.

x = 42
name = "Bloa"
is_active = true
list = [1, 2, 3]
pi = 3.14159

Operators

Arithmetic

  • +Addition
  • -Subtraction
  • *Multiplication
  • /Division
  • %Modulo
  • ^Power

Comparison

  • ==Equal
  • !=Not equal
  • <Less than
  • >Greater than
  • <=Less or equal
  • >=Greater or equal

Logical

  • andLogical AND
  • orLogical OR
  • notLogical NOT

Control Flow

If/Else

if x > 10 {
  say("x is greater than 10")
} else if x == 10 {
  say("x is 10")
} else {
  say("x is less than 10")
}

While Loop

i = 0
while i < 5 {
  say("i = " + str(i))
  i = i + 1
}

For Loop

for i = 0; i < 5; i = i + 1 {
  say("i = " + str(i))
}

Functions

function greet(name) {
  say("Hello, " + name + "!")
}

function add(a, b) {
  return a + b
}

greet("Bloa")
result = add(5, 3)
say("5 + 3 = " + str(result))

Classes

class Person {
  function __init__(self, name, age) {
    self.name = name
    self.age = age
  }

  function greet(self) {
    say("Hi, I'm " + self.name)
  }
}

person = Person("Alice", 30)
person.greet()

Modules

Import external modules with the import keyword:

import math
import utils.helpers

result = math.sqrt(16)
say("sqrt(16) = " + str(result))
say(i) i = i + 1 }

For-in Loop

for item in [1, 2, 3, 4, 5] {
  say(item)
}

Repeat Loop

repeat 3 {
  say("Hello!")
}

Functions

Functions are reusable blocks of code that can take parameters and return values.

function add(a, b) {
  return a + b
}

result = add(5, 3)
say(result)  # Output: 8

Classes

Bloa supports object-oriented programming with classes and inheritance.

class Animal {
  function __init__(self, name) {
    self.name = name
  }

  function speak(self) {
    say(self.name + " makes a sound")
  }
}

dog = Animal("Buddy")
dog.speak()  # Output: Buddy makes a sound

Modules

Organize your code into modules for better maintainability.

use "math"

result = math.sqrt(16)
say(result)  # Output: 4

Built-in Functions

Bloa provides many useful built-in functions:

say(value)

Print output to console

ask(prompt)

Read user input

type(value)

Get the type of a value

len(collection)

Get length of string/list/dict

Standard Library

The standard library provides extensive functionality for common tasks. Explore the dedicated modules for detailed information.