[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advanced Programming Structures



Robert S Ely (rsely74@optonline.net) wrote: 

: I've written some fairly large BASIC XE programs and CAN'T avoid the use
: of the GOTO command. However, at least BXE has named subroutines and
: procedures. You can also GOTO linename or at least add a REM line in the
: code to state what the point of access is to do. I use to do that, but
: it takes up valuable memory. 

GOTO can be very useful.  In particular for simulating an IF...THEN...ELSE:

100 IF K% <> 255 THEN 150
110 IF LEN (Q1$)<2 THEN Q1$="":GOTO 200
120 Q1$=RIGHT$(Q1$,2)
130 GOTO 200

150 Q1$=Q1$+CHR$(K%-128)

200 VTAB V:POKE 36,H:PRINT Q1$;" ";Q2$;" ";

Which is the equivalent of:

 IF K%=255 THEN
     IF LEN (Q1$)<2 THEN Q1$=""
     ELSE
     Q1$=RIGHT$(Q1$,2)
     ENDIF
 ELSE
     Q1$=Q1$+CHR$(K%-128)
 ENDIF
 VTAB V:POKE 36,H
PRINT Q1$;" ";Q2$;" "

I suppose if you really don't want to use GOTO you could simulate it using
a tactic we use in 6502 Assembler to avoid using JMP: 

           SEC
           BCS JumpTo ;Simulating a JMP JumpTo
      (code to be skipped)
JUMPTO     (code continues here)

In BASIC you could do the same thing:

2300 Q=5 : IF Q=5 THEN 2400
2305 REM Skipped code (probably an ELSE emulation) continues here
2400 REM Continue here

...But why would you want to other than to avoid using GOTO?  In Assembler
there is a definite reason...BCS is relocatable because it is a relative
jump while JMP is absolute.  But in BASIC it's just the waste of eight
tokens and a perfectly good variable.

: 570 REM [some small code to do something]

: .
: .
: .
: 1530 if x=y goto 572

: Now this may look like a procedure call or a sub routine, but it may do
: some specific task that can't be done as a specific routine call. I
: don't happen to have any examples on-hand at the moment. I call this glue
: code to stick program parts together. It's rare, but necessary at times. 

You mean something like some of my input routines:

60000 Q1$=""
60001 (actual string input routine sits here, outputs to Q1$)
6000n RETURN

In some cases I enter the routine at 60000, to provide the user a blank
input field.  Or, if there is a default value, I put the default value in
Q1$ and enter the routine at 60001.  By the way, the input routine loop is
built with a GOTO, with an IF K%=141 THEN 6000n to exit.  Anybody who
programs in Applesoft probably recognizes K% as containing the value from
the soft switch at $C000... 8-)

--Dave Althoff, ][.
-- 
    /X\        _       _               _  *** Now open every day! ***
   /XXX\      /X\     /X\_      _     /X\__      _     _        _____  
  /XXXXX\    /XXX\  _/XXXX\_   /X\   /XXXXX\    /X\   /X\      /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX