Language Syntax

Kode has a clean, readable syntax inspired by modern programming languages. This guide covers the basic syntax elements.

Variables and Constants

Use let to declare mutable variables:

kode
let x = 10
let name = "Kode"
let active = true

Use const for immutable constants:

kode
const PI = 3.14159
const APP_NAME = "My App"

Data Types

Kode supports several built-in types:

  • int - Integer numbers
  • float - Floating-point numbers
  • string - Text strings
  • bool - Boolean values (true/false)
  • []T - Arrays of type T

Functions

Functions are declared with the fn keyword:

kode
fn add(a: int, b: int) -> int {
    return a + b
}

fn greet(name: string) {
    print("Hello, " + name)
}

Control Flow

If Statements

kode
if x > 10 {
    print("x is greater than 10")
} else if x > 5 {
    print("x is greater than 5")
} else {
    print("x is 5 or less")
}

For Loops

kode
for let i = 0; i < 10; i++ {
    print(i)
}

While Loops

kode
let i = 0
while i < 10 {
    print(i)
    i++
}

Arrays

kode
let numbers = [1, 2, 3, 4, 5]
let names = ["Alice", "Bob", "Charlie"]

// Access elements
let first = numbers[0]

// Add elements
numbers.push(6)

// Get length
let len = numbers.length

Comments

kode
// This is a single-line comment

/*
This is a multi-line comment
that spans multiple lines
*/