Usage of GET-NEXT inside DO WHILE loop

I want to skip the code execution in certain cases within DO WHILE loop.

Code:
DO WHILE NOT QUERY-OFF-END('NameOfQuery'):
   code to execute
   code to execute
   IF .... THEN DO:
      code to execute
      code to execute
      IF ... THEN GET NEXT NameOfQuery.  /* if TRUE then skip the rest of the code and process next query result */
      code to skip
      code to skip
   END.
   code to skip
   code to skip
GET NEXT NameOfQuery.
END. /* end skip */
I have a 'DO WHILE NOT QUERY-OFF-END' loop, inside this loop there is another 'IF .... THEN DO' loop, inside this loop there is IF condition and if it's TRUE then I would like to skip the execution of the rest of the code beginning from first comment and start processing next (GET NEXT) result from query.
Would such piece of code will do code skipping as described?
 

Cringer

ProgressTalk.com Moderator
Staff member
I think that what you have there isn't fully complete. I would do this:

Code:
MyNamedBlock:
DO WHILE NOT QUERY-OFF-END('NameOfQuery'):
   code to execute
   code to execute
   IF .... THEN DO:
      code to execute
      code to execute
      IF ... THEN DO: GET NEXT NameOfQuery. Next MyNamedBlock. END.
  /* if TRUE then skip the rest of the code and process next query result */
      code to skip
      code to skip
   END.
   code to skip
   code to skip
GET NEXT NameOfQuery.
END. /* end skip */

I've not tested this, but it shouldn't be hard for you to test.
 
If I understand your approach then:

1. My code will execute inside DO WHILE loop a GET NEXT statement but it will go on with the rest of the code in the loop. However the code after GET NEXT statement will be using the NEXT record from Query.

2. Your code will execute a GET NEXT statement inside DO WHILE loop, and then will go to the next block named: MyNamedBlock. But isn't it possible to tell a DO WHILE loop to start execute next pass of loop, inside this loop? If it will be possible then there will be no need to call 'goto' statement.

Anyway in both cases, before GET NEXT statement inside DO WHILE loop I will need to check if there is available NEXT result from QUERY using QUERY-OFF-END.
 

TomBascom

Curmudgeon
This sounds closer to what you want to me:

Code:
DO WHILE true:

   GET NEXT NameOfQuery.

   code to execute
   code to execute

   IF .... THEN DO:

      code to execute
      code to execute

      IF ... THEN next.    /*** GET NEXT NameOfQuery.  ***/ /* if TRUE then skip the rest of the code and process next query result */

      code to skip
      code to skip

   END.

   code to skip
   code to skip

  if  QUERY-OFF-END('NameOfQuery') then leave.

END. /* end skip */
 
This sounds closer to what you want to me:

Code:
DO WHILE true:

   GET NEXT NameOfQuery.

   code to execute
   code to execute

   IF .... THEN DO:

      code to execute
      code to execute

      IF ... THEN next.    /*** GET NEXT NameOfQuery.  ***/ /* if TRUE then skip the rest of the code and process next query result */

      code to skip
      code to skip

   END.

   code to skip
   code to skip

  if  QUERY-OFF-END('NameOfQuery') then leave.

END. /* end skip */

Yes, NEXT statement will do the Job but only if there is no nested DO WHILE loop. If I will have DO WHILE or other ITERATION loop which is nested, then NEXT will reference to this loop. In this case I will need to use 'goto' statement.
It will be much better if I will be able to give a name to the loop and then when using NEXT statement call the name. i.e.

Code:
DO (MyLoop) WHILE....:
   DO (OtherLoop) WHILE....:
      NEXT (MyLoop)
   END.
END...
Such enhancement will be very useful.

Thanks to all for answer. Now I know what possibilities I have.

P.S. As usually I need to say 'great community'.
 

TomBascom

Curmudgeon
That enhancement has been a core part of the language from day 1:

Code:
MyLoop: DO WHILE....:
   OtherLoop: DO WHILE....:
      NEXT MyLoop.
   END.
END.

I didn't show it because the problem, as you stated it, didn't seem to need to worry about nested blocks.
 
That enhancement has been a core part of the language from day 1:

Code:
MyLoop: DO WHILE....:
   OtherLoop: DO WHILE....:
      NEXT MyLoop.
   END.
END.

I didn't show it because the problem, as you stated it, didn't seem to need to worry about nested blocks.
Nice. This is what I was looking for. This is the same resolution as posted by Cringer. The only difference is that this one is written in one line.

Now there should be an enhacement to this forum allowing to change the topic and add a [SOLVED] word.

Once again. Thank you.
 
Top