Pauses the program and waits for keyboard input. The entered text is echoed to the terminal and then stored in variable.
- variable may be string, integer, or real.
- If the input is not valid for the requested type (for example, letters when an integer is expected), the variable is set to 0.
- INPUT is blocking: execution does not continue until the user presses Enter.
The INPUT statement is intentionally simple. For richer line-editing (cursor keys, history, etc.) see the ansi library, which also lets you manage your own I/O loop.
Examples
Read a number
PRINT "Enter a number:"
INPUT N
PRINT "You typed: "; N
Handle invalid numeric input
PRINT "Enter an integer:"
INPUT I
IF I = 0 THEN
PRINT "That was not a valid integer (or it was zero)."
ELSE
PRINT "OK: "; I
ENDIF
Read a string
PRINT "Enter your name:"
INPUT NAME$
PRINT "Hello, "; NAME$
Prompt until non-zero
REPEAT
PRINT "Enter a non-zero value:"
INPUT X
UNTIL X <> 0
PRINT "Thanks: "; X
Notes
- The entered line is stored as-is for string variables (without the trailing newline).
- For numeric variables, parsing is strict; invalid input yields 0.
- INPUT echoes characters to the terminal. For full-screen UI or advanced editing, prefer the ansi library.