[next] [previous] [contents]

  2.3 Immediate Mode
  You do not have to write a complete program in BASIC.
  Many statements are executable in immediate mode.

  Immediate mode statements are BASIC statements that
  are executed immediately after you press the Return key.
  Immediate mode statements cannot be preceded by a line
  number, space, or tab and can be used only if you are work-
  ing directly in the environment.

  In the following example, VAX BASIC interprets the first line
  as a comment because it begins with an exclamation point
  ( ! ). VAX BASIC interprets the second line as part of a larger
  program because it begins with a line number. This line does
  not execute until a RUN command is specified. The third line
  does not begin with a line number, a space, or an exclama-
  tion point. Therefore, BASIC treats the line as an immediate
  mode statement and immediately displays the specified text.
  !In the environment, this is a comment



                                                            Return




  10 PRINT 'This is an executable BASIC statement'

                                                                            Return




  PRINT 'THIS IS AN IMMEDIATE MODE STATEMENT'

                                                                    Return




  Output
  THIS IS AN IMMEDIATE MODE STATEMENT
  Ready
  The Ready prompt indicates that VAX BASIC is ready to re-
  ceive compiler commands, immediate mode statements, or
  new program lines.

  You can precede each executable statement with a backslash
  ( \ ). You can also have more than one BASIC statement on a
  line if you separate the statements with a backslash character
  as in the following example:
  Ready
  A = (54.37 / 1.25 ) \ B = ( 328.15^2) \ PRINT ( B / A )

    2475.69

  Unless a STOP statement is executed, VAX BASIC compiles
  and executes each immediate mode statement as if it were a
  self-contained program. For example:
  Ready
  PRINT PI * 67.3

    211.421

  Even if the current program executes a STOP statement, you
  can perform independent calculations. However, after a stop,
  any immediate mode statement referencing program vari-
  ables uses the values assigned in the program. Note that you
  cannot create new program variables after a STOP statement
  has been executed.

  If the current program does not execute a STOP statement,
  each immediate mode line exists by itself, and any vari-
  ables used by the statements on that line are temporary. For
  example:
  Ready
  A = 2^5 \ PRINT A

    32
  READY
  PRINT A

    0

  The second PRINT statement instructs VAX BASIC to dis-
  play zero because the compiler treats A as a new variable and
  initializes it to zero.

  You can use the IF, WHILE, UNTIL, UNLESS, and FOR
  statement modifiers in immediate mode statements. The fol-
  lowing example shows how you can generate a table of square
  roots by using the immediate mode statement:
  Ready
  PRINT I, SQR (I) FOR I = 1 TO 10

    1 1
    2 1.41421
    3 1.73205
    4 2
    5 2.23607
    6 2.44949
    7 2.64575
    8 2.82843
    9 3
    10 3.16228
  Ready

  Certain statements are invalid in immediate mode. In gen-
  eral, invalid statements are statements that require the
  allocation of new storage, or statements that do not make
  sense in the context of a single line. If you try to execute such
  a statement, BASIC signals the error ``Illegal in immediate
  mode''.