Intermec PC43d Fingerprint Developer's Guide (PC23d, PC43d/t, PM23c, PM43, PM4 - Page 30

Instructions for Conditional Branching, Using an IF...THEN GOTO...ELSE Instruction, Using an ON...

Page 30 highlights

Chapter 2 - Understanding Fingerprint Syntax The next example illustrates nested subroutines: 10 20 30 40 1000 1010 1020 1030 2000 2010 2020 2030 3000 3010 3020 RUN PRINT "This is the main program" GOSUB 1000 PRINT "You're back in the main program" END PRINT "This is subroutine 1" GOSUB 2000 PRINT "You're back from subroutine 2 to 1" RETURN PRINT "This is subroutine 2" GOSUB 3000 PRINT "You're back from subroutine 3 to 2" RETURN PRINT "This is subroutine 3" PRINT "You're leaving subroutine 3" RETURN Instructions for Conditional Branching Conditional branching means that the program execution branches to a certain line or subroutine when a specified condition is met. The following instructions are used for conditional branching: Using an IF...THEN GOTO...ELSE Instruction If a specified condition is TRUE, the program branches to a certain line, but if the condition is FALSE, something else is done as shown in the next example: 10 INPUT "Enter a value: ",A% 20 INPUT "Enter another value: ",B% 30 IF A%=B% THEN GOTO 100 ELSE PRINT "NOT EQUAL" 40 END 100 PRINT "EQUAL" 110 GOTO 40 RUN Using an ON...GOSUB Instruction Depending on the value of a numeric expression, the execution branches to one of several subroutines. If the value is 1, the program branches to the first subroutine in the instruction, if the value is 2 it branches to the second subroutine, and so on. The next example includes such an instruction: 10 20 30 1000 2000 3000 RUN INPUT "Press key 1, 2, or 3 on host: ", A% ON A% GOSUB 1000, 2000, 3000 END PRINT "You have pressed key 1": RETURN PRINT "You have pressed key 2": RETURN PRINT "You have pressed key 3": RETURN Using an ON...GOTO Instruction This instruction is similar to ON...GOSUB but the program branches to specified lines instead of subroutines. This implies that you cannot use RETURN statements to go back to the main program. 18 Fingerprint Developer's Guide

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163

Chapter 2 — Understanding Fingerprint Syntax
18
Fingerprint Developer’s Guide
The next example illustrates nested subroutines:
10
PRINT “This is the main program”
20
GOSUB 1000
30
PRINT “You’re back in the main program”
40
END
1000
PRINT “This is subroutine 1”
1010
GOSUB 2000
1020
PRINT “You’re back from subroutine 2 to 1”
1030
RETURN
2000
PRINT “This is subroutine 2”
2010
GOSUB 3000
2020
PRINT “You’re back from subroutine 3 to 2”
2030
RETURN
3000
PRINT “This is subroutine 3”
3010
PRINT “You’re leaving subroutine 3”
3020
RETURN
RUN
Instructions for Conditional Branching
Conditional branching means that the program execution branches to a certain line
or subroutine when a specified condition is met. The following instructions are used
for conditional branching:
Using an IF...THEN GOTO...ELSE Instruction
If a specified condition is TRUE, the program branches to a certain line, but if the
condition is FALSE, something else is done as shown in the next example:
10
INPUT “Enter a value: ”,A%
20
INPUT “Enter another value: ”,B%
30
IF A%=B% THEN GOTO 100 ELSE PRINT “NOT EQUAL”
40
END
100
PRINT “EQUAL”
110
GOTO 40
RUN
Using an ON...GOSUB Instruction
Depending on the value of a numeric expression, the execution branches to one of
several subroutines. If the value is 1, the program branches to the first subroutine in
the instruction, if the value is 2 it branches to the second subroutine, and so on. The
next example includes such an instruction:
10
INPUT “Press key 1, 2, or 3 on host: ”, A%
20
ON A% GOSUB 1000, 2000, 3000
30
END
1000
PRINT “You have pressed key 1”: RETURN
2000
PRINT “You have pressed key 2”: RETURN
3000
PRINT “You have pressed key 3”: RETURN
RUN
Using an ON...GOTO Instruction
This instruction is similar to ON...GOSUB but the program branches to specified
lines instead of subroutines. This implies that you cannot use RETURN statements
to go back to the main program.