Skip to content

Printing

Printing is a way to write to the terminal. There are 3 ways to print in Cranberry, but the most used ones are the following:

Print some values followed by a newline (\n).

Print some values without making a newline.


The print and println functions are builtin functions that you can call with parentheses and any values inside it will be outputed to the terminal.

The below code will print “Hello” and “World” in separate lines:

println("Hello")
println("World")
Hello
World

The below code will print “Hello” and “World” in the same line:

print("Hello")
print("World")
HelloWorld

Simply add more arguments with commas in between. The print functions can take infinitely many arguments. Each value will have a space in between it.

println("hello", "world", "foo", "bar")
hello world foo bar

Or use formatted strings:

println($"Hello {1 + 1}")
Hello 2