Intermec PB51 Fingerprint Developer's Guide (old) - Page 34

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

Page 34 highlights

Chapter 2 - Understanding Fingerprint Syntax • background communication is interrupted. You can also branch to a subroutine from different places in the same program. You only need to write the routine once, making the program more compact. The instruction for unconditional branching to subroutines is the GOSUB statement. After branching, the subroutine is executed line by line until a RETURN statement is encountered. The same subroutine can be branched to as often as needed from different lines in the main program. GOSUB remembers where the last branching took place, which makes it possible to return to the correct line in the main program after the subroutine has been executed. Subroutines may be nested, which means that a subroutine may contain a GOSUB statement for branching to a secondary subroutine. Subroutines should be placed on lines with higher numbers than the main program. Append the main program with an END statement to avoid unintentional execution of subroutines. 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 18 Intermec 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
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187

Chapter 2 — Understanding Fingerprint Syntax
18
Intermec Fingerprint Developer’s Guide
background communication is interrupted.
You can also branch to a subroutine from different places in the same program. You
only need to write the routine once, making the program more compact.
The instruction for unconditional branching to subroutines is the GOSUB
statement. After branching, the subroutine is executed line by line until a RETURN
statement is encountered.
The same subroutine can be branched to as often as needed from different lines in
the main program. GOSUB remembers where the last branching took place, which
makes it possible to return to the correct line in the main program after the
subroutine has been executed. Subroutines may be nested, which means that a
subroutine may contain a GOSUB statement for branching to a secondary
subroutine.
Subroutines should be placed on lines with higher numbers than the main program.
Append the main program with an END statement to avoid unintentional
execution of subroutines.
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