LEARN VOID / 01

Syntax basics

Read your first VOID program.

Complete program for the synchronous entry adapter. The result below is the returned integer.

syntax.voidDownload source
# Three items fit in each box.
func entry(boxes: i32) -> i32:
    return boxes * 3
Input 4Expected result 12

Read the function declaration

func entry(boxes: i32) -> i32: names a function, its integer input and its integer result. Here a box holds three items, so four boxes produce 12 items.

Use indentation for the body

The colon starts the body; indent its statements by four spaces. return boxes * 3 calculates and returns the item count. Ordinary blocks need no braces or statement-ending semicolons. A # comment explains the idea without affecting execution.

Understand the entry adapter

The current command-line adapter passes one i32 input to entry and displays its returned integer. The first example uses that adapter; the compiler selects the application entry below from its checked source. Use console.stdout for explicit output. Use descriptive lowercase snake_case names.

Choose an application entry point

For application execution, use voidc run main.void with a zero-argument synchronous main(). A main without a result exits successfully; a main returning i32 must return on every path. This short application deliberately returns status seven. That status belongs to the process and is not printed; standard output is empty. No numeric adapter input is passed.

main.voidDownload source
func main() -> i32:
    return 7
Exit status 7Standard output empty

Executable top-level statements are an alternative to main, not something to combine with it. This source executes in order and returns success when capacity is available. Run it with voidc run top-level.void.

top-level.voidDownload source
var capacity = 24
var reserved = 6
var available = capacity - reserved
return if available > 0:
    0
else:
    1
Exit status 0Standard output empty

Top-level fallthrough or a bare return means status zero. File-level globals initialize before main or top-level execution. Nested block variables stay local, and imported modules cannot contain executable statements. Use the async host adapter for an async numeric entry. Application status and console output are independent.