27220 Parallax Inc, 27220 Datasheet - Page 26

BOOK STAMPWORKS

27220

Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet

Specifications of 27220

Accessory Type
Booklet
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
StampWorks
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Not applicable / Not applicable
The STEP option of FOR-NEXT is used when the loop needs to count in increments
other than one. If, for example, the loop needed to count even numbers, the code
would look something like this:
SUBROUTINES – REUSABLE CODE THAT SAVES PROGRAM SPACE
The final programming concept we’ll discuss is the subroutine. A subroutine is a
section of code that can be called from anywhere in the program. GOSUB is used to
redirect the program to the subroutine code. The subroutine is terminated with the
RETURN instruction. RETURN causes the program to jump back to the line of code
that follows the calling GOSUB.
In this example, the code in the My_Sub subroutine is executed and then the
program jumps back to the line PAUSE 1000.
Advanced programmers will take advantage of subroutines and the ON-GOSUB
instruction. ON-GOSUB works like ON-GOTO, except that the program returns to the
line that follows ON-GOSUB. This technique is very useful for creating
program structures as shown next:
FOR counter = 2 TO 20 STEP 2
NEXT
Start:
My_Sub:
Main:
statement 1
statement 2
statement 3
DO
LOOP
statement 1
statement 2
statement 3
RETURN
DO
LOOP
GOSUB My_Sub
PAUSE 1000
GOSUB Critical_Task
ON task GOSUB Task_1, Task_2, Task_3
task = task + 1 // 3
task manager

Related parts for 27220