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?â
- Variables and Types - Learn about data storage
- Control Flow - Add logic to your programs