How to come out of If Else statement without using Goto in Powerbuilder

staarship
staarship used Ask the Experts™
on
I have a certain piece of code which is of the following format

--------------------
--------------------
            For ll_count = 1 to dw_1.Rowcount
                --------------
                ---------------
                 If <condition> Then
                       ---------------------
                       -----------------------
                       Go To Label;
                       ------------------
                       ---------------------
                    End If
                --------------------
                --------------------
          Next
Label:

-------------
----------------


I want to come out of the If Statement and directly execute the code after the Label
without looping in the For loop.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
use exit in place of go to lable.
Read pb help for exit for more detail. It exits from current loop only. If you inner loops, exit will help to come out only from that loop. In such case you will need to handle code using some variables.

Regards,
Sandeep

Author

Commented:
Re-writtng the code again with some additional statements before the label and after the next statement of for loop..next:

--------------------
            For ll_count = 1 to dw_1.Rowcount
                --------------
                 If <condition> Then
                       -----------------------
                       Go To Label;
                       ---------------------
                    End If
                --------------------
          Next
----------- some more code over here before the label
-----------
Label:
-------------

In this case, if i use exit in place of goto, then the control will jump immediately to the next line after the "Next" statement, whereas i want it to jump directly to the Label.. I am trying this because i am migrating my code from client/server to web using PB 11.5.. and GOTO is not supported on web..

As I mentioned you should be able to handle the flow with the help of variables. Not sure about the code immediately after For loop should be executed always or not, but you can write something like this. There are many different ways to handle this depending on the way code is written.

boolean lb_pass = FALSE
--------------------
            For ll_count = 1 to dw_1.Rowcount
                --------------
                 If <condition> Then
                       -----------------------
                       lb_pass = TRUE;
                       Exit;
                       ---------------------
                    End If
                --------------------
          Next

If not lb_pass Then
----------- some more code over here before the label
-----------
End If
Label:
-------------

Regards,
Sandeep

Author

Commented:
Solution can be applied easily and can be integrated successfully..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial