Page 159 - Learn to Program - Basic-256
P. 159

Chapter 10: Functions and Subroutines – Reusing Code.                           Page 143


                   Program 68 shows an example of a subroutine that is called three times.




                1       # gosub.kbs
                2       # a simple gosub
                3
                4       a = 10
                5       for t = 1 to 3
                6          print "a equals " + a
                7          gosub showline
                8       next t
                9       end
                10
                11      showline:
                12      print "------------------"
                13      a = a * 2
                14      return
            Program 68: Gosub




                   a equals 10
                   ------------------
                   a equals 20
                   ------------------
                   a equals 40
                   ------------------
            Sample Output 68: Gosub




















                                                           © 2019 James M. Reneau (CC BY-NC-SA 3.0 US)
   154   155   156   157   158   159   160   161   162   163   164