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:
println()
Section titled “println()”Print some values followed by a newline (
\n
).
print()
Section titled “print()”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.
Examples
Section titled “Examples”The below code will print “Hello” and “World” in separate lines:
println("Hello")println("World")
HelloWorld
The below code will print “Hello” and “World” in the same line:
print("Hello")print("World")
HelloWorld
Printing Multiple Values
Section titled “Printing Multiple Values”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