Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
PRINT?991.0+Command and Statement
Note the Abbreviation is literaly a question mark (?).

 
 
Syntax 
PRINT [ { , | ; } ] ... [ { expression TAB(n) SPC(n) } [ { , | ; } [ { expression TAB(n) SPC(n) } ] ] ... ]
 
ParametersTypeLegal Value(s)Default ValueNote(s)
expressionany
any
 
 
nNumeric 0 ~ 255   
 
 
Purpose 
Print an expression(s) to the current output device.

 
 
Remarks 
PRINT is pretty versatile; it will accept any number or type of expressions. The number of expressions is limited only by the length of a BASIC program line; you may have zero expressions.  Each expression may be of numeric or string type; each may be a literal value (e.g., the number 7 or the string "hello"), a variable, a simple function (such as ABS(X) or STR$(X)), or a "BASIC forumula" (which includes actual mathematical forumulas, such as 2*X+1, and so-called "string formulas" like A$+CHR$(X)).
 
Besides printing an expression, you may also "print" spaces (code 32) with the SPC(n) preposition or "cursor right"(s) (code 29) with the TAB(n) preposition.  If the value of n is not legal (see above) then an ILLEGAL QUANTITY ERROR is generated.  The SPC preposition will add n spaces after the last expression (if any).  The TAB preposition will add enough "cursor rights" so that the resulting column equals (0-based) column n; if the output has already exceeded column n then no "cursror rights" are output.  Note the TAB preposition works well with the screen (because the system always knows the on-screen cursor position) but is unreliable when sending to another device...
 
By default, PRINT sends its output to the active display screen (the C128 has two display screens and one is active; all other CBMs only have one screen which is always active).  Output may be redirected to other devices; see CMD.
 
The optional comma (,) will seperate surrounding expressions by a "virtual tab stop" which occurs once every 10 columns.  Note most CBM machines do not have Tab stops on the display screen; the C128 does have Tab stops (which may be defined anywhere) but they are ignored by PRINT (it always uses the 10-column rule).  If a PRINT statement ends with a comma, the output is set to the next "virtual tab stop" and no "new line" (see below) is sent to the output device.
 
The optional semicolon (;) will not separate surrounding expressions; the will "run together".  This is obvious with strings (see examples), but most numerical expressions will appear separated because PRINT will include a trailing space behind each number, and positive numbers (which are very common) will have a leading space.  (See STR$ for details about how BASIC formats numeric values.)  I hate to complicate things, but (contrary to the Syntax shown above) BASIC will often allow you to omit a semicolon with the same effect as including one between two expressions; this is possible when there is no ambiguity between two expressions.  To be nagative, this makes for hard-to-read (sloppy) code, but on the positive side this feature allows programs to be more compact (thus less memory use and faster execution).  Anyway, if a PRINT statement ends with a semicolon, the output position is not changed; that is, no "new line" (see below) is sent to the output device.
 
If the statement does not end with one of the two optional punctuation marks (a comma or semicolon), then PRINT will end by sending a "new line" to the output device.  By default, this is a terminating carriage return (code 13).  Under some cases (see OPEN) it may also send a terminating line feed (code 10).
 
Some versions of BASIC (those > 2) allow a USING clause which allows for further customization of how each expression is generated.
 
PRINT itself cannot generate an error, however any invalid expression will generate an error (for example SYNTAX ERROR, or TYPE MISMATCH ERROR); this also applies to the n parameter of the SPC and TAB prepositions.
 
When printing to the screen (the default case), a huge number of secret variables may be changed by "printing" control codes; see the ASCII-X or PETSCII page for a list of many of those codes.
  
Examples:
?29+35
 64  

READY.
10 PRINT "HELLO",
20 PRINT "WORLD"
RUN
HELLO     WORLD

READY.
NEW

READY.
10 PRINT "HELLO";
20 PRINT "WORLD"
RUN
HELLOWORLD

READY.
NEW

READY.
10 PRINT "HELLO"
20 PRINT "WORLD"
RUN
HELLO
WORLD

READY.
NEW

READY.
10 PRINT "HELLO" TAB(8);  :REM no punctuation (implied ;) between HELLO & TAB
20 PRINT "WORLD"
RUN
HELLO   WORLD           note HELLO at column 0, WORLD at column 8

READY.
 
 
Compare With 
CHAR, CMD, PRINT# 
  
 
Contrast With 
INPUTREAD 
 
 
See Also 

© H2Obsession, 2014