Skip to content

Language Reference Statement PRINT

Andreas AFENTAKIS edited this page Oct 7, 2025 · 1 revision

Language Reference, Statement: PRINT

Purpose

The primary function of the PRINT statement is to send to the output handler text, variables, and the results of expressions. The default handler is the standard output, so will be visible to the user's screen.

Syntax

The basic syntax is:

PRINT [expression | variable | value ] [{;} ]

Only one variable, value or expression can be used in each print statment.

Parameters

The PRINT statement accepts one or more items to display.

Type Description Example
String Literal Text enclosed in double quotes ("). "Hello World"
Numeric Variable A variable holding an integer or floating-point number. A, TotalSales
String Variable A variable holding text or number. N, CustomerName
Expression A mathematical calculation or logical operation. (5 * X) / 2

Newline Behavior

By default, every PRINT statement executes a newline (carriage return/line feed) after its output is complete, moving the cursor to the start of the next line.

  • To suppress this newline, simply end the PRINT statement with a comma (,) or a semicolon (;).
Code Resulting Screen Output
basic PRINT "Part 1" PRINT "Part 2" Part 1
Part 2
basic PRINT "Part 1"; PRINT "Part 2" Part 1Part 2

Newline at the end of the PRINT content

The semicolon (;) at the end of a PRINT statement in FBASIC is a print-zone control character that suppresses the automatic newline (carriage return and line feed) that normally occurs after a PRINT statement executes.

Effect of the Semicolon

  • Standard PRINT: If a PRINT statement does not end with a semicolon, the output device's cursor/print position moves to the beginning of the next line after the statement finishes.

    PRINT "Hello"
    PRINT "World"
    ' Output:
    ' Hello
    ' World
  • PRINT with Semicolon: If a PRINT statement ends with a semicolon (;), the output device's cursor/print position remains immediately following the last item printed on the current line.

    PRINT "Hello";
    PRINT "World"
    ' Output:
    ' HelloWorld
  • Concatenation/Spacing: When used between items within a single PRINT statement, the semicolon acts as a delimiter that causes the items to be printed immediately adjacent to each other, without any intervening spaces (unless the data type naturally includes a trailing space, like positive numbers in some BASICs).

  • It's primarily used to concatenate output from multiple PRINT statements onto a single line or to control the spacing between different variables or string literals being printed.


Output handler

Output Handler: The .NET Delegate for Content Delivery

The Output (Print) Handler serves as the vital intermediary between the execution of a BASIC PRINT statement and the actual output medium. In a modern compiler or interpreter leveraging the .NET framework, the PRINT command does not directly perform screen I/O. Instead, it relies on a .NET delegate to manage content delivery.

This delegate, typically structured as the following code, defines the contract for consuming the generated output text. When a PRINT statement finishes processing its variables and expressions, it invokes this registered delegate, passing the finalized string content as a parameter.

    public delegate void PrintFunction(string text);

The major benefit of this delegate-based approach is complete decoupling. The interpreter engine doesn't need to know if it's running in a command-line environment, a desktop application, or a web server. Developers can easily plug in different handler methods: one to write to Console.Out, another to append text to a graphical user interface (GUI) log window, or even one to enqueue messages for network transmission. This modularity ensures the system is highly testable and incredibly adaptable, allowing the classic PRINT functionality to integrate seamlessly into any sophisticated .NET application architecture.

Clone this wiki locally