PRINT Statement ---------------------------------------------------------------------------- Action Outputs data to the screen. Syntax PRINT expressionlist {;|,} Remarks If expressionlist is omitted, a blank line is displayed. If expressionlist is included, the values of its expressions are printed on the screen. The PRINT statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- expressionlist The values that are displayed on the screen. The argument expressionlist can contain numeric or string expressions. String Argument Description ---------------------------------------------------------------------------- or string expressions. String literals must be enclosed in quotation marks. {;|,} Determines the screen location of the text cursor for the next screen input or output statement. a semicolon means the text cursor is placed immediately after the last character displayed; a comma means the text cursor is placed at the start of the next print zone. The PRINT statement supports only elementary BASIC data types (integers, long integers, single-precision real numbers, double-precision real numbers, currency, and strings). To print information from a record, use individual record-element names in the PRINT statement, as in the following code fragment. TYPE MyType Word AS STRING * 20 Count AS LONG END TYPE DIM Myrec AS MyType PRINT Myrec.Word Item-Format Rules A printed number always is followed by a space. If the number is positive, it also is preceded by a space; if the number is negative, it is preceded by a minus sign (-). If a single-precision number can be expressed as seven or fewer digits with no loss of accuracy, then it is printed in fixed-point format; otherwise, floating-point format is used. For example, the number 1.1E-6 is output displayed as .0000011, but the number 1.1E-7 is output as 1.1E-7. If a double-precision number can be expressed with 15 or fewer digits and no loss of accuracy, it is printed in fixed-point format; otherwise, floating-point format is used. For example, the number 1.1D-14 is displayed as .000000000000011, but the number 1.1D-15 is output as 1.1D-15. Print-Line Format Rules The print line is divided into print zones of 14 spaces each. The position of each printed item is determined by the punctuation used to separate the items in expressionlist. a comma makes the next value print at the start of the next zone; a semicolon makes the next value print immediately after the last value. Using one or more spaces or tabs between expressions has the same effect as using a semicolon. If a comma or a semicolon terminates the list of expressions, the next PRINT statement to execute prints on the same line, after spacing accordingly. If the expression list ends without a comma or a semicolon, a carriage-return-and-line-feed sequence is printed at the end of the line. If the printed line is wider than the screen width, BASIC goes to the next physical line and continues printing. See Also PRINT #, PRINT USING, WIDTH Examples The following examples show the use of commas and semicolons with PRINT. First is an example of using commas in a PRINT statement to print each value at the beginning of the next print zone. CLS ' Clear screen. X = 5 PRINT X + 5, X - 5, X * (-5), X ^ 5 END Output 10 0 -25 3125 In the second example, the semicolon at the end of the first PRINT statement makes the first two PRINT statements display output on the same line. The last PRINT statement prints a blank line before the next prompt. CLS ' Clear screen. DO INPUT "Input X (type 0 to quit). ", X IF X = 0 THEN EXIT DO ELSE PRINT X; "squared is"; X ^ 2; "and"; PRINT X; "cubed is"; X^3 PRINT END IF LOOP Output Input X (type 0 to quit). 9 9 squared is 81 and 9 cubed is 729 Input X (type 0 to quit). 21 21 squared is 441 and 21 cubed is 9261 Input X (type 0 to quit). 0 In the third example, the semicolons in the PRINT statement print each value immediately after the preceding value. Note that a space always follows a number and precedes a positive number. CLS ' Clear screen. FOR X = 1 TO 5 J = J + 5 K = K + 10 PRINT J; K; NEXT X Output 5 10 10 20 15 30 20 40 25 50