print Statement
Syntax
┌───── ";" ◄────┐
▼ │
"print" ───► Expression ─┴─┬───────────► EOL
│ ▲
└─► ";" ──┘
Usage
The
print statement is the simplest way to display something on the screen.
Each
print statement produces a line of text on the screen.
The following example displays two lines of text:
First line! and
Second line!.
After printing the two lines, the cursor is positioned on the third line, ready for the next line of printed output.
┌─ Code ───────────────────────────────────┐ ╔═ Console ═══════════════╗
│sub Main() │ ║First line! ║
│ print "First line!" │ ║Second line! ║
│ print "Second line!" │ ║█ ║
│end sub │ ║ ║
└──────────────────────────────────────────┘ ╚═════════════════════════╝
To display multiple things on the same line, place a semicolon at the end of the statement.
Then, the cursor will remain at the end of the line so that further text can be printed on the same line.
print "Hello ";
print "world!"
As a shortcut, you can combine these statements into one:
The
print statement can display the contents of variables.
dim name = "John"
dim age = 52
print "Hello, "; name; "! You are "; age; " years old!"
When used together with the
input statement, a program can have an interactive conversation with the user.
┌─ Code ───────────────────────────────────┐ ╔═ Console ═══════════════╗
│sub Main() │ ║Pythagorean Theorem ║
│ print "Pythagorean Theorem" │ ║Enter the side lengths. ║
│ print "Enter the side lengths." │ ║Leg A: 3 ║
│ │ ║Leg B: 4 ║
│ print "Leg A: "; │ ║Hypotenuse is 5 ║
│ dim a as Number │ ║█ ║
│ input a │ ║ ║
│ │ ║ ║
│ print "Leg B: "; │ ║ ║
│ dim b as Number │ ║ ║
│ input b │ ║ ║
│ │ ║ ║
│ dim c = Sqr(a^2 + b^2) │ ║ ║
│ print "Hypotenuse is "; c │ ║ ║
│end sub │ ║ ║
└──────────────────────────────────────────┘ ╚═════════════════════════╝