Function Definition
Functions are reusable blocks of code that perform specific tasks. In Stellartrails, you define a function using the fn
keyword, followed by the function name, parameters in parentheses, and a code block. Functions help organize code, avoid repetition, and make programs easier to read and maintain.
A function can take zero or more parameters and may return a value. The function body contains the statements to execute when the function is called.
Example
fn greet(name: String) {
print("Hello, " + name)
}
greet("World")
In this example, the greet
function takes a single parameter and prints a greeting message. You can call functions multiple times with different arguments.