11.07.2015 Views

Here - 1000 BiT

Here - 1000 BiT

Here - 1000 BiT

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

^ INSTRUCTOR NOTES 24 PRETTY PROGRAMS, GOSUB, RETURN, END^ This lesson covers subroutines. The END command is also treated here because theprogram will usually have its subroutines at high line numbers and so must END in themiddle line numbers.Like GOTO, GOSUB causes a jump to another line number. The only difference is that inr^ GOSUB, control returns to the calling line after the subroutine is finished executing. Thisis accomplished by storing the line number following the GOSUB line on a stack. WhenO the computer encounters a RETURN statement, it pops the line number off the stack andreturns control to that line.^ Subroutines are useful not only in long programs but also in short ones where "chunking"the task into sections leads to clarity.One of the hardest habits to form in some students (and even some professionals) is to^ impose structure on the program. Structuring has gone by many names such as"structured programming" and "top down programming" and uses various techniques toDdiscipline the programmer.Call the student's attention to ways in which structuring can be done, and the advantagesr*\ in clarity of thought and ease of programming which result. In this book, writing goodREM statements and using modular construction in the program are the main techniques^offered.^QUESTIONS:O 1. What happens when the command END is executed?^ 2. How is GOSUB different from GOTO?3. What happens when RETURN is executed?o ■ ■■ -■■■■ •4. If RETURN is executed before GOSUB, what happens?n ■ ■ . ■ " '-■ " ■■■', '.5. What does "call the subroutine" mean?^ 6. How many END commands are you allowed to put into one program?^ 7. Why do you want to have subroutines in your programs?nnn135

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!