Skip to main content

Basic Syntax

This chapter covers the fundamental syntax elements of Rive.

Comments​

// This is a single-line comment

/*
* This is a
* multi-line comment
*/

Functions​

Every Rive program starts with a main function:

fun main() {
print("Hello, Rive!")
}

Function Structure​

fun function_name(parameter: Type) -> ReturnType {
// function body
return value
}

Example:

fun greet(name: Text) {
print("Hello, " + name)
}

fun add(a: Int, b: Int): Int {
return a + b
}

Statements and Expressions​

Statements are instructions that perform actions:

print("Hello")        // Statement
let x = 5 // Statement

Expressions produce values:

5 + 3                  // Expression: evaluates to 8
"Hello" + " World" // Expression: evaluates to "Hello World"

Code Blocks​

Code blocks are enclosed in curly braces {}:

fun main() {
print("Start")
print("Middle")
print("End")
}

What's Next?​