IN Statement

Fetches a single character from the keyboard and returns its ASCII code.

Syntax

IN variable {FOR time [ THEN statement(s) | ELSE statement(s) ]}

Syntax Elements

variable A variable or array element to which the value or string entered is assigned.

FOR timeOptionally specifies how long the system waits for input before returning. time is specified in tenths of a second as a integer between 1 and 30,000.

  • If time is less than 1 or the FOR clause is omitted, the result is no time-out.

  • For values greater than 30,000, 30,000 is used.

A value of 30,000 corresponds to 50 minutes.

Note

This behaviour can be changed with the INPUTTOUT compatibility option.

statement(s) A sequence of one or more valid DataBasic statements, either separated by semicolons, or contained on separate lines and followed by an END statement.

The circumstances under which the different clauses are executed are as follows:

THEN Executed if input is completed within time.

ELSE Executed if input is not completed within time.

Operation

The IN statement does not display a prompt, nor does it require a terminating return or linefeed. Characters entered are not echoed to the screen.

Note

This behaviour can be changed with the ECHO.IN compatibility option.

A character is retrieved from the type-ahead buffer without being processed and is converted to its equivalent decimal value before being assigned to the variable. For example, if the backspace key is pressed, the IN statement returns 8; if the return key is pressed, the value returned is 13.

Examples

LOOP
   IN KEY
UNTIL KEY = 13 DO REPEAT

This example loops until the return key is pressed.

TIMELIMIT = 300 ;* 30 SECONDS
IN KEY FOR TIMELIMIT ELSE
   CRT "TIMEOUT OCCURRED"
   STOP
END

In this example, the IN statement waits for a key to be pressed. If no key is pressed within 30 seconds, the message TIMEOUT OCCURRED is displayed and the program stops.

See Also

INPUT statement, INPUT@ statement.