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

About Loops, Using a FOR...NEXT Instruction

Page 34 highlights

Chapter 2 - Understanding Fingerprint Syntax About Loops One type of loop has already been described in connection with the GOTO statement, where GOTO referred to the same line or a previous line. There are two instructions for using more advanced loops: Using a FOR...NEXT Instruction These statements create loops in which a counter is incremented or decremented until a specified value is reached. The counter is defined by a FOR statement as follows: FOR=TO [STEP]NEXT[] All program lines following the FOR statement are executed until a NEXT statement is encountered. Then the counter (specified by a numeric variable) will be updated according to the optional STEP value (or by the default value +1) and the loop is executed again. This is repeated until the final value, as specified by TO , is reached. Then the loop is terminated and the execution proceeds from the statement following the NEXT statement. FOR...NEXT loops can be nested, which means a loop can contain another loop. Each loop must have a unique counter designation in the form of a numeric variable. The NEXT statement makes the execution loop back to the most recent FOR statement. To loop back to a different FOR statement, the corresponding NEXT statement must include the same counter designation as the FOR statement. This example shows how five lines of text entered from the host keyboard can be printed with an even spacing: 10 FONT "Univers" 20 FOR Y%=220 TO 100 STEP -30 30 LINE INPUT "Type text: ";TEXT$ 40 PRPOS 100, Y% 50 PRTXT TEXT$ 60 NEXT 70 PRINTFEED 80 END RUN The next example includes two nested FOR...NEXT loops: 10 FOR A%=20 TO 40 STEP 20 20 FOR B%=1 TO 2 30 PRINT A%,B% 40 NEXT : NEXT A% RUN This results in: 20 1 20 2 40 1 40 2 This example shows how to create an incremental counter: 10 INPUT "Start Value: ", A% 20 INPUT "Number of labels: ", B% 30 INPUT "Increment: ", C% 22 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
22
Fingerprint Developer’s Guide
About Loops
One type of loop has already been described in connection with the GOTO
statement, where GOTO referred to the same line or a previous line. There are two
instructions for using more advanced loops:
Using a FOR...NEXT Instruction
These statements create loops in which a counter is incremented or decremented
until a specified value is reached. The counter is defined by a FOR statement as
follows:
FOR<
counter
>=<
start value
>TO
<
final value
>[STEP<±
interval
>]NEXT[<counter>]
All program lines following the FOR statement are executed until a NEXT
statement is encountered. Then the counter (specified by a numeric variable) will be
updated according to the optional STEP value (or by the default value +1) and the
loop is executed again. This is repeated until the final value, as specified by TO
<final value>, is reached. Then the loop is terminated and the execution proceeds
from the statement following the NEXT statement.
FOR...NEXT loops can be nested, which means a loop can contain another loop.
Each loop must have a unique counter designation in the form of a numeric
variable. The NEXT statement makes the execution loop back to the most recent
FOR statement. To loop back to a different FOR statement, the corresponding
NEXT statement must include the same counter designation as the FOR statement.
This example shows how five lines of text entered from the host keyboard can be
printed with an even spacing:
10
FONT “Univers”
20
FOR Y%=220 TO 100 STEP -30
30
LINE INPUT “Type text: ”;TEXT$
40
PRPOS 100, Y%
50
PRTXT TEXT$
60
NEXT
70
PRINTFEED
80
END
RUN
The next example includes two nested FOR...NEXT loops:
10
FOR A%=20 TO 40 STEP 20
20
FOR B%=1 TO 2
30
PRINT A%,B%
40
NEXT : NEXT A%
RUN
This results in:
20
1
20
2
40
1
40
2
This example shows how to create an incremental counter:
10
INPUT “Start Value: ”, A%
20
INPUT “Number of labels: ”, B%
30
INPUT “Increment: ”, C%