PRINT - display a message to the screen or window.
Syntax
PRINT message
- message - message to be displayed.
Description
PRINT displays a message on the screen. This message can be a string, number, or even the contents of a variable.
Examples
Example of Use
PRINT is most commonly used to print a simple message to the player as a string.
PRINT "The game has begun. Run for your freekin' life!"
PRINTING Blank Lines
If you use PRINT by itself, you can print blank lines :
PRINT "Line 1"
PRINT
PRINT "Line 3"
You can paste together two PRINT statements together with colon and thus save space in your code when you want to display more than one blank line :
PRINT:PRINT
PRINT "Line 3"
Display numbers
PRINT can display numbers and the result of mathematical calculations.
PRINT 103
PRINT 103 + 3
It can do this even if one of the numbers is contained in a variable.
DIM number
number = 10
PRINT 32 + number
Displaying the contents of variables using PRINT is very helpful for debugging.
Printing Multiple Bits of Data
You can print multiple chunks of data using the semicolon.
DIM playerName AS STRING
DIM hitPoints AS INTEGER
playerName = "Optimas Primus"
hitPonts = 1000
PRINT "Hello, "; playerName
PRINT "You have "; hitPoints; " hit points".
The output of this code is :
Hello, Optimas Primus
You have 1000 hit points.
Alternately, you can put semicolons at the end of each PRINT statement.
PRINT "This appears ";
PRINT "as one line."
The output of this code is :
This appears as one line.
Formatting Output
Using the comma ( ,) you can cause each chunk to be displayed in it's own zone, usually around 14 spaces apart. This is useful if you want to format the information.
PRINT "Health : "; health, "Gold : "; gold
PRINT "Location : "; location, "Points : "; points
Question Mark ( ? ) as Shorthand
In some BASICs, a question mark and be used as shorthand (or an abbreviation) for PRINT. Both lines below are identical as far as what each line does :
? "Using a question mark saves typing 4 letters"
PRINT "Using a question mark saves typing 4 letters"
Related Pages
- WRITE - almost exactly like PRINT's evil twin.
Backlinks
These pages link back to this page.
Links
- Print and {{Printr at the Basic4GL Wiki