|$99||1.0||Command and Statement|
Print a numeric or string value on the text screen.
The keyword PRINT may be abbreviated with a question mark (?).
If nothing follows the keyword, then BASIC will set the current cursor position to the start of the next line by simply printing a carriage return (character $0D = CHR$(13)).
value may be a literal, variable, or an expression of either numeric or string type.
PRINT :REM start a new line PRINT 1.5 :REM numeric literal PRINT X :REM numeric variable PRINT 2*X :REM numeric expression PRINT LEFT$(N$,12) :REM string expression PRINT N$ :REM string variable PRINT "HELLO" :REM string literal PRINT "HELLO
Literal strings must be surrounded by double quotes (”) unless the line would end with a double quote, in which case the trailing one may be omitted (last two examples above). A double quote may not be used in a string literal, however variables and expressions can be created that have a double quote as shown below.
NEW 10 A$="HELLO" 20 PRINT "SAY "; CHR$(34); A$; CHR$(34) RUN SAY "HELLO" READY.
No leading or trailing spaces are normally generated when printing a string value. When printing a numeric value, a positive number will print with a leading space (the same position would be a - for a negative number), and a trailing cursor_right regardless of sign.
It is not clear why Commodore used cursor_right (character $1D = CHR$(29)) instead of a space. Normally this appears as a space on screen, but if quote mode or insert mode is active, it will instead appear as a reverse-font right bracket ”]”. If printing is redirected (see CMD) this may cause problems for some devices. Examination of C1541 ROMs (and similar) reveals they had to special-case this obscure character.
These spacing rules generally mean that spacing before and after numeric values is automatic while the programmer must explictily add spaces for string values where needed. The automatic spacing after a numeric value can be a problem if at the end of sentence or phrase (when a comma or other punction should immediately follow the number). One solution is to print a cursor_left or delete character (codes $9D = CHR$(157) and $14 = CHR$(20) respectively) after the number to back-up the printing position by one character; this can cause problems similar to cursor_right noted above. Another solution is to first convert the numeric value into a string with STR$() and then print the string; the string will not have the trailing cursor_right.
Printing normally occurs immediately at the current cursor position. Printing may directed to start at a further position to the right by preceding value with one or more commas ”,”. Semicolons ”;” may also precede value but have no effect. Each preceding comma will cause value to start printing at the next BASIC tab stop.
PRINT 7 :REM print at current cursor position PRINT ;7 :REM print at current cursor position PRINT ,7 :REM print at next tab position (usually column 10) PRINT ,,7 :REM print two tab stop over (usually column 20)
Multiple values may be printed by seperating each with a comma or semicolon. The semicolon specifies the new value to follow immediately after the last, while a comma specifies the next BASIC tab stop. A semicolon may be omitted if value is a string literal.
NEW 10 PRINT 1,2 30 PRINT 3;4 50 PRINT 5 "EGGS" 60 PRINT 6;"LOGS" 70 PRINT 7,"BRICKS" 80 PRINT "NOT"; "ICE" 90 PRINT "NOT", "ICE" RUN 1 2 3 4 5 EGGS 6 LOGS 7 BRICKS NOTICE NOT ICE READY.
Multiple values may also be seperated with the SPC() or TAB() prepositions / functions (semantically they operate as prepositions seperating multiple values, while logically they are string functions). The argument to SPC is a count of “space” characters to follow the last output, while the argument to TAB is a zero-based column value. With both functions, BASIC will actually output cursor_right characters (see note above). If the argument to TAB is less than or equal to the current cursor position then no cursor_right characters are printed between values.
10 PRINT "0123456789" 20 PRINT "OVER" SPC(6) "THERE" 30 PRINT "OVER" TAB(6) "THERE" 40 PRINT "OVER" TAB(2) "THERE" RUN 0123456789 OVER THERE OVER THERE OVERTHERE READY.
After the value(s) are printed, BASIC will normally print a carriage return (character $0D = CHR$(13)) so that the next PRINT command will occur at the first column of the next line. However this may be supressed by ending the command with a semicolon ”;”. Printing may be directed to resume at the next tab stop(s) by preceding the final semicolon with comma(s) ”,”.
PRINT 7 :REM next PRINT occurs on a new line PRINT 7; :REM next PRINT occurs on the same line, just after the 7 PRINT 7,; :REM next PRINT occurs on the same line, next tab stop after 7
BASIC tab stops are 10 characters apart; they are internally maintained and can not be changed from length of 10 characters (the C128 text screen editor and most printers allow tab stops to be customized but BASIC will have no clue). This feature has two problems.
The first is that BASIC prints numeric values with up to 9 digits of precision. When including the leading sign (minus or space) and the trailing cursor_right this results in 11 characters. Values this long will normally have a decimal point as well leading to a length up to 12 characters. So often multiple numeric values will be spaced two tab positions apart – but BASIC does not print trailing zeros in fractions so a numeric value may be less than 10 characters (so only one tab position apart). The result is that numeric values seperated by commas will print at “random” positions on screen (depending on how many digits follow the decimal point)!
The second problem is that aligning the printing position to a specific BASIC tab stop is not achieved by use of a tab (character $09 = CHR$(9)) or with space characters, but with multiple cursor_right characters. When printing to the screen, these will result in reverse-font right bracket ”]” characters if insert or quote mode is active, and may cause unpredictable behavior if output has been redirected to another device (see CMD).
Many of these problems can be avoided in newer versions of BASIC with the USING preposition.
This page is a member of Commodore BASIC