PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Question about the end clause of a select / next record loop  (Read 1332 times)

Ken Sproul

  • Gold Member
  • ****
  • Posts: 60
    • View Profile
Question about the end clause of a select / next record loop
« on: August 20, 2019, 03:01:45 PM »
Is an expression used in the end clause of a select / next record loop evaluated at every iteration?
Ken Sproul
DPI Information Service, Inc.
Pivotal Systems LLC

keith.mcbride

  • Member
  • **
  • Posts: 12
    • View Profile
Re: Question about the end clause of a select / next record loop
« Reply #1 on: August 20, 2019, 04:32:17 PM »
Ken, Interesting question.  I wrote the following program:

0100 BEGIN
0110 OPEN (1)"*MEMORY*"
0120 OPEN (2)"/tmp/test"
0200 FOR i=1 TO 10
0205 WRITE (1,KEY=STR(i:"00"))i
0210 NEXT i
0215 c=10
0300 SELECT i FROM 1 BEGIN "" END STR(c:"00")
0305 PRINT (2)"I=",i," C=",c
0310 c-=1
0320 NEXT RECORD

If the END is only evaluated once at the beginning then I expect it to read all 10 records, ignoring the new value of C
If the END is evaluated each iteration, then I would expect the program to stop reading somewhere around record 6 or 5.

The results:
I= 1 C= 10
I= 2 C= 9
I= 3 C= 8
I= 4 C= 7
I= 5 C= 6
I= 6 C= 5
I= 7 C= 4
I= 8 C= 3
I= 9 C= 2
I= 10 C= 1

It would appear that the end is only evaluated once at the beginning of the SELECT

Keith

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: Question about the end clause of a select / next record loop
« Reply #2 on: August 20, 2019, 04:49:46 PM »
The BEGIN and END on a SELECT are evaluated once at the beginning.
Principal Software Engineer for PVX Plus Technologies LTD.

Ken Sproul

  • Gold Member
  • ****
  • Posts: 60
    • View Profile
Re: Question about the end clause of a select / next record loop
« Reply #3 on: August 20, 2019, 05:21:36 PM »
Thanks Keith and Devon.  I thought at least the end clause was evaluated each time.  This is actually good news, because I was trying to avoid complex expressions in the end clause for performance reasons, but since it's only evaluated once, I don't have to worry about that.
Ken Sproul
DPI Information Service, Inc.
Pivotal Systems LLC