User Tools

Site Tools


simulating_20resume_20and_20resume_20next

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

simulating_20resume_20and_20resume_20next [2018/03/31 13:19]
127.0.0.1 external edit
simulating_20resume_20and_20resume_20next [2018/04/17 18:51] (current)
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //by Richard Russell, September 2007//\\ \\  BBC BASIC doesn'​t have the **RESUME** and **RESUME NEXT** statements sometimes found in other dialects of BASIC. Although there are alternative (and probably better) ways of achieving a similar effect when writing a program from scratch, their absence can be inconvenient when translating programs from another dialect. This article describes how a very similar effect can be achieved in //BBC BASIC for Windows// (version 5.60a or later).\\ \\  Firstly let's review what RESUME and RESUME NEXT do. They are intended for use in an error handler (i.e. a routine activated by **ON ERROR**) and cause execution to continue at the statement that resulted in the error (in the case of **RESUME**) or the statement following the one that resulted in the error (in the case of **RESUME NEXT**).\\ \\  Here is a simple **GW-BASIC** or **QBASIC** program which illustrates the use of RESUME (//​don'​t//​ try to run it in **BBC BASIC**!):​\\ \\  //by Richard Russell, September 2007//\\ \\  BBC BASIC doesn'​t have the **RESUME** and **RESUME NEXT** statements sometimes found in other dialects of BASIC. Although there are alternative (and probably better) ways of achieving a similar effect when writing a program from scratch, their absence can be inconvenient when translating programs from another dialect. This article describes how a very similar effect can be achieved in //BBC BASIC for Windows// (version 5.60a or later).\\ \\  Firstly let's review what RESUME and RESUME NEXT do. They are intended for use in an error handler (i.e. a routine activated by **ON ERROR**) and cause execution to continue at the statement that resulted in the error (in the case of **RESUME**) or the statement following the one that resulted in the error (in the case of **RESUME NEXT**).\\ \\  Here is a simple **GW-BASIC** or **QBASIC** program which illustrates the use of RESUME (//​don'​t//​ try to run it in **BBC BASIC**!):​\\ \\ 
 +<code qbasic>
         PRINT "​Program starting"​         PRINT "​Program starting"​
         ON ERROR GOTO 1000         ON ERROR GOTO 1000
Line 13: Line 14:
         Divisor = 3         Divisor = 3
         RESUME         RESUME
 +</​code>​
 When run the program generates the following output:\\ \\  When run the program generates the following output:\\ \\ 
   Program starting   Program starting
Line 20: Line 22:
   Program finished   Program finished
 Note that an error occurs (division by zero) because **Divisor** is initially zero, but in the error handler **Divisor** is changed to 3 and the division is repeated, this time successfully.\\ \\  Here is the same program in //BBC BASIC for Windows// using some sneaky code to reproduce the effect of **RESUME**:​\\ \\  Note that an error occurs (division by zero) because **Divisor** is initially zero, but in the error handler **Divisor** is changed to 3 and the division is repeated, this time successfully.\\ \\  Here is the same program in //BBC BASIC for Windows// using some sneaky code to reproduce the effect of **RESUME**:​\\ \\ 
 +<code bb4w>
         PRINT "​Program starting"​         PRINT "​Program starting"​
         ON ERROR GOTO 1000         ON ERROR GOTO 1000
Line 34: Line 37:
         WHILE ?P% AND P% + ?P% < !408 P% += ?P% : ENDWHILE         WHILE ?P% AND P% + ?P% < !408 P% += ?P% : ENDWHILE
         GOTO (P%)         GOTO (P%)
 +</​code>​
 This code produces the following output:\\ \\  This code produces the following output:\\ \\ 
   Program starting   Program starting
Line 46: Line 50:
   Program finished   Program finished
 Here the division isn't repeated, and the RESUME NEXT transfers control to the "PRINT "​Program finished""​ line.\\ \\  Here is the equivalent program in //BBC BASIC for Windows//:​\\ \\  Here the division isn't repeated, and the RESUME NEXT transfers control to the "PRINT "​Program finished""​ line.\\ \\  Here is the equivalent program in //BBC BASIC for Windows//:​\\ \\ 
 +<code bb4w>
         PRINT "​Program starting"​         PRINT "​Program starting"​
         ON ERROR GOTO 1000         ON ERROR GOTO 1000
Line 60: Line 65:
         REPEAT P% += ?P% : UNTIL ?P% = 0 OR P% > !408         REPEAT P% += ?P% : UNTIL ?P% = 0 OR P% > !408
         GOTO (P%)         GOTO (P%)
 +</​code>​
 And here is the output:\\ \\  And here is the output:\\ \\ 
   Program starting   Program starting
simulating_20resume_20and_20resume_20next.txt ยท Last modified: 2018/04/17 18:51 by tbest3112