INPUT

BASin

INPUT

Statement/Command

INPUT enables data to be entered during the running of a program.

How to use INPUT

INPUT normally forms a statement in a program and is used in a very similar way to PRINT. In its simplest form, it is followed by a numeric or string variable, for example

60 INPUT x
70 INPUT a$

The computer then waits until either a number or a string is entered. The value is displayed at the beginning of the bottom line as it is keyed in. On pressing ENTER, the value is assigned to the named variable and the program continues.

An INPUT statement may include more than one variable and will display characters to form a prompt. This is done in exactly the same way as with PRINT, using quote marks to enclose the prompt characters and semicolons or commas as necessary to separate items. Display statements such as INK, FLASH and PAPER may be embedded, for example

80 INPUT INK 2;"What is your name?";n$,("How old are you, "+n$+"?" ");age

Note the following differences to PRINT. INPUT waits when it comes to a variable, so all variables and expressions (such as that including n$ above) which are to be included in prompts must be enclosed in brackets. Display begins at the start of the bottom line and then scrolls up if more than one line is used. AT may be used in an INPUT statement in the same way as with PRINT. Used with INPUT, AT 0,0 displays at the start of the line above the bottom line and the display scrolls up if more than two lines are displayed.

How to halt INPUT

If INPUT is followed by a numeric variable and STOP is entered, then the program stops. With a string variable, the first quote mark that appears may be deleted and then STOP entered to halt the program.

Using INPUT with LINE

INPUT LINE may be used with string variables only. Normally, INPUT with a string variable causes a pair of quotes to be displayed. As the string is keyed in, it appears between the quotes. To remove these quotes, use INPUT LINE followed by the string variable. If a prompt is required, it is placed between the INPUT and LINE, for example

70 INPUT "What is your name? "; LINE n$

Format

  • INPUT [prompt] [;] [,] ['] num-var
  • INPUT [prompt] [;] [,] ['] string-var
  • INPUT [prompt] [;] [,] ['] LINE num-var

See also

Chapter 2, Chapter 15.