The Program is:
!find position of B for various n for pos and posr functions
!Note error in text page 125, for posr(Target$,pattern$,position) he
!states that position "equal to 1 means the last character in Target$,
!so position increases in value as you move to the left". Actually,
!position is always measured from the left, as shown below.
LET n=0
PRINT "In string ABCDEABCDEABCDE"
DO until n >= 15
LET n=n+1
LET position = posr("ABCDEABCDEABCDE","B",n)
SET COLOR "red"
PRINT "for n= ";n;" in posr(,,n) the position of B is...";position
LOOP
LET n=0
DO until n >= 15
LET n=n+1
LET position = pos("ABCDEABCDEABCDE","B",n)
SET COLOR "blue"
PRINT "for n= ";n;" pos(,,n) the position of B is...";position
LOOP
END
The output is:
In string ABCDEABCDEABCDE
for n= 1 in posr(,,n) the position of B is... 0
for n= 2 in posr(,,n) the position of B is... 2
for n= 3 in posr(,,n) the position of B is... 2
for n= 4 in posr(,,n) the position of B is... 2
for n= 5 in posr(,,n) the position of B is... 2
for n= 6 in posr(,,n) the position of B is... 2
for n= 7 in posr(,,n) the position of B is... 7
for n= 8 in posr(,,n) the position of B is... 7
for n= 9 in posr(,,n) the position of B is... 7
for n= 10 in posr(,,n) the position of B is... 7
for n= 11 in posr(,,n) the position of B is... 7
for n= 12 in posr(,,n) the position of B is... 12
for n= 13 in posr(,,n) the position of B is... 12
for n= 14 in posr(,,n) the position of B is... 12
for n= 15 in posr(,,n) the position of B is... 12
for n= 1 pos(,,n) the position of B is... 2
for n= 2 pos(,,n) the position of B is... 2
for n= 3 pos(,,n) the position of B is... 7
for n= 4 pos(,,n) the position of B is... 7
for n= 5 pos(,,n) the position of B is... 7
for n= 6 pos(,,n) the position of B is... 7
for n= 7 pos(,,n) the position of B is... 7
for n= 8 pos(,,n) the position of B is... 12
for n= 9 pos(,,n) the position of B is... 12
for n= 10 pos(,,n) the position of B is... 12
for n= 11 pos(,,n) the position of B is... 12
for n= 12 pos(,,n) the position of B is... 12
for n= 13 pos(,,n) the position of B is... 0
for n= 14 pos(,,n) the position of B is... 0
for n= 15 pos(,,n) the position of B is... 0