Thursday, July 18

ON...GOTO Statement

The ON...GOTO Statement is used to branch to one of several specified line numbers depending on the value return, when an expression is evaluated.
Syntax
LN ON expression GOTO line numbers
Where,
LN      :  Line Number
Expression  :  Valid numeric expression
Line number  :  Line numbers to where jump has to take place.

  • In the ON...GOTO statement the value of expression determines which line number in the list will be used for branching.
For example  :
If the value of expression =3, the third will be the destination of the branch.

  • If value expression is zero the execution continues with next executable statement in the program.
  • If value of expression is negative or greater than 255, error 0 classes.
Examples
1.  100 ON  N  GOTO  200, 300, 400
2.  150 ON  M  GOTO  215, 50, 300
In Example 1, the branching takes place depending on the value of N
if N=1, the program branches to line 200
if N=2, the program  branches to line 300
if N= 3, the program branches to line 400 and so on.

START
A =1
PRINT A  (infinite loop)
N
A = A+1     

Note : The program displays the number 1,2,3... and so on infinitely (forming infinite loop)
1.  Press Pause key to stop the display of numbers temporarily.
2.  Press CTRL+Break to stop to the execution of the program (or to terminate the infinite loop)


CS 7.2 Display on the screen for GOTO statement

Ok
LIST
10   REM Learning the use of GOTO statment
20   CLS
30   LET A =1
40   PRINT A
50   LET A = A+1
60   GOTO 40
70   END
Ok    
            

No comments:

Post a Comment