# Language tour

> A fast tour of Langoost syntax — variables, types, functions, control flow, arrays, objects, template strings, classes, and error handling, with runnable examples.

# Language tour

A quick pass over the core syntax. Each topic has a dedicated page with more
detail; follow the links as you go.

## Comments & statements

Single-line comments use `//` (there are no block comments). Statements are
separated by newlines or semicolons; newlines inside `(...)` and `[...]` are
ignored, so expressions can span lines.

```goost
// this is a comment
```

## Variables

Declare with `let`; the type annotation is optional and inferred from the value:

```goost
let name = "alice"          // inferred string
let age: int = 30           // explicit annotation
let active: bool = true
```

Reassign with `=`, `+=`, or `-=`. Variables are block-scoped. See
**[types & values](/docs/types)** for the full type list and number literals
(`0xFF`, `0b1010`, `1_000`).

## Functions

```goost
fn greet(name: string): string {
    return "Hello, " + name + "!"
}

let double = fn(x) { return x * 2 }   // anonymous function
```

Top-level functions are hoisted, support recursion and variadics (`...args`),
and are first-class values. See **[functions](/docs/functions)**.

## Strings

Concatenate with `+`, or interpolate with backtick **template strings**:

```goost
let user = "Ada"
println("Hi, " + user)
println(`Hi, ${user} — ${3 + 4} new messages`)
```

Strings and arrays carry methods like `.upper()`, `.split()`, `.map()` —
see **[value methods](/docs/methods)**.

## Operators

```goost
1 + 2 - 3 * 4 / 2 % 3      // arithmetic (+ also concatenates strings)
a == b   a != b   a < b    // comparison
a && b   a || b   !a       // logical, short-circuiting
a & b    a | b    a ^ b    // bitwise and / or / xor
a << n   a >> n   ~a       // shift left / right, bitwise not
```

## Control flow

`if / else if / else`, `while`, and `for..in` (over arrays or `range`), with
`break` and `continue`:

```goost
for i in range(10) {
    if i == 3 { continue }
    if i == 7 { break }
    println(i)
}
```

More in **[control flow](/docs/control-flow)**.

## Arrays & objects

```goost
let nums = [1, 2, 3]
nums = append(nums, 4)
let evens = nums.filter(fn(n) { return n % 2 == 0 })

let user = {name: "alice", age: 30}
println(user.name)
```

See **[arrays](/docs/arrays)** and **[classes & types](/docs/classes)**.

## Classes & errors

Langoost has classes with single inheritance, runtime-checked interfaces
(`is` / `as`), and `try` / `catch` / `throw` / `finally` / `defer` for error
handling:

```goost
class Dog extends Animal {
    fn speak() { return "woof" }
}

try {
    risky()
} catch err {
    println("failed: " + toString(err))
} finally {
    cleanup()
}
```

See **[classes & types](/docs/classes)** and **[error handling](/docs/error-handling)**.

## Imports

```goost
import strings
import { abs, sqrt } from "math"

strings.upper("hi")     // "HI"
println(sqrt(16.0))     // 4
```

See **[modules & imports](/docs/modules)** and the
**[standard library](/docs/stdlib)** — strings, http, json, crypto, sql, and more.

## Built-in functions

Always in scope without an import: `print`, `println`, `len`, `toString`,
`toInt`, `toFloat`, `range`, `typeof`, `append`, `read`, `exit`.