You still have to use an "IF" to test for condition.  There is no other 
_practical_ way.  If you want to devise a way to avoid "IF", it will be 
convoluted and be created for no good purpose other than to avoid the use of 
"IF"..

The previous suggestion of testing for a Boolean or marker value upon exiting 
the while via the break statement is the most direct sensible method.

You should use a label in the "IF" block that will take you to your clean-up 
code (You still need to go here usually applying good programming practice), 
bypassing the other code..


----- Original Message ----- 
From: "Jan Barley" <[EMAIL PROTECTED]>
To: "RBG7-L Mailing List" <[email protected]>
Sent: Friday, August 05, 2005 8:07 PM
Subject: [RBG7-L] - Re: exiting a WHILE loop in an eep


> James,
> In a case like this, I use a label to go to.  For example:
>
> dec jan cur for sel blah blah blah
> open jan
> fet jan into x1, x2 ....
> whi sqlcode <> 100 then
>  do whatever you want
>  if it fails, then
>    goto endjan
>  endi
>  rest of loop
> fet jan into x1, x2....
> endw
> drop cur jan
> *(do something else here...)
> label endjan
> return
>
> You can place the label anywhere in the command file you want to go to on
> your break.
> Does this help you???
>
> Jan Barley
>
>
>
>
> ----- Original Message ----- 
> From: "James Hageman" <[EMAIL PROTECTED]>
> To: "RBG7-L Mailing List" <[email protected]>
> Sent: Friday, August 05, 2005 7:17 PM
> Subject: [RBG7-L] - Re: exiting a WHILE loop in an eep
>
>
>> It's the code that follows the while loop I am trying to avoid if I
>> break out of the while loop before it terminates normally.
>>
>> I know I can break out and then use an if statement to check how the
>> while loop was terminated but I was hoping there was a different way.
>>
>>
>>
>>
>>
>>
>>
>> On Aug 5, 2005, at 5:06 PM, Albert Berry wrote:
>>
>> > James, the only safe way to exit a loop is using BREAK.  A RETURN
>> > inside a WHILE loop is an
>> > accident waiting to happen. Without seeing all your code, It is
>> > possible that you could use the
>> > following WHILE statement:
>> >
>> > WHILE SQLCODE <> 100 AND vEscape <> 'T' THEN
>> >
>> > You could also use an IF;ELSE;ENDIF inside the loop to skip over
>> > the code you don't want to run.
>> >
>> > --- James Hageman <[EMAIL PROTECTED]> wrote:
>> >
>> >
>> >> But that would just put me outside the while loop and I don't want
>> >> any
>> >> more code to run if I BREAK out of the while loop.
>> >>
>> >> I could do this, put the same IF/ENDIF inside and outside of the
>> >> while
>> >> loop but it seems silly.
>> >>
>> >> WHILE ...
>> >>  IF vescape = 'T' THEN
>> >>      BREAK
>> >>   ENDIF
>> >> ENDWHILE
>> >> IF vescape = 'T' THEN
>> >>    return
>> >> ENDIF
>> >> other code ....
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> Albert Berry wrote:
>> >>
>> >>
>> >>> I believe you would be safer if you replaced part of the code
>> >>> with 'BREAK'
>> >>>
>> >>> DECLARE c1 SCROLL CURSOR FOR SELECT ...
>> >>> OPEN c1
>> >>> WHILE SQLCODE <> 100 THEN
>> >>>  FETCH c1 INTO ...
>> >>> -- This has already been covered in the WHILE ...
>> >>> --  IF SQLCODE = 100 THEN
>> >>> --    BREAK
>> >>> --  ENDIF
>> >>>  INSERT INTO ...
>> >>>  EDIT USING ...
>> >>> -- At this point, a BREAK would be cleaner
>> >>>  IF vescape = 'T' THEN
>> >>>     BREAK
>> >>>  ENDIF
>> >>>
>> >>> ENDWHILE
>> >>> CLEAR ALL V
>> >>> DROP CURSOR c1
>> >>> RETURN         <-- THIS OK?
>> >>>
>> >>>
>> >>> --- James Hageman <[EMAIL PROTECTED]> wrote:
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>> The following code runs with no errors but I am wondering if
>> >>>> it's Kosher.
>> >>>> Specificaly if vescape = 't' and I return to the form that calls
>> >>>> the eep
>> >>>> in the middle of the while loop is that going to cause problems
>> >>>> for me
>> >>>> later?
>> >>>>
>> >>>> ----------------------------------------------------------------
>> >>>> --other code blah blah
>> >>>> --
>> >>>> DECLARE c1 SCROLL CURSOR FOR SELECT ...
>> >>>> OPEN c1
>> >>>> WHILE SQLCODE <> 100 THEN
>> >>>>  FETCH c1 INTO ...
>> >>>>  IF SQLCODE = 100 THEN
>> >>>>    BREAK
>> >>>>  ENDIF
>> >>>>  INSERT INTO ...
>> >>>>  EDIT USING ...
>> >>>>
>> >>>>  IF vescape = 'T' THEN
>> >>>>    CLEAR ALL V
>> >>>>    DROP CURSOR c1
>> >>>>    RETURN         <-- THIS OK?
>> >>>>  ENDIF
>> >>>>
>> >>>> ENDWHILE
>> >>>> DROP CURSOR c1
>> >>>>
>> >>>> --other code follows that I don't want run if VAR vescape = 'T'
>> >>>> ...
>> >>>> ...
>> >>>> ...
>> >>>> return
>> >>>> --eof---------------------------------------------------------
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>>
>> >>> Albert Berry
>> >>> Management Consultant
>> >>> RR2 - 1252 Ponderosa Drive
>> >>> Sparwood BC, V0B 2G2
>> >>> Canada
>> >>> (250) 425-5806
>> >>> (250) 425-7259
>> >>> (708) 575-3952 (fax)
>> >>> [EMAIL PROTECTED]
>> >>>
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >>
>> >
>> >
>> > Albert Berry
>> > Management Consultant
>> > RR2 - 1252 Ponderosa Drive
>> > Sparwood BC, V0B 2G2
>> > Canada
>> > (250) 425-5806
>> > (250) 425-7259
>> > (708) 575-3952 (fax)
>> > [EMAIL PROTECTED]
>> >
>> >
>>
>>
> 

Reply via email to