Exit condition in loop

I am putting exit condition in before and after my business logic, so it make any difference
BEGIN
     FOR REC IN 1..10
     LOOP
          EXIT WHEN REC =5;
          business logic
     END LOOP;
END;
BEGIN
     FOR REC IN 1..10
     LOOP
          business logic
          EXIT WHEN REC =5;
     END LOOP;
END;Thanks
Edited by: Braam on Oct 11, 2012 10:24 PM

Would have been quicker for you to test it yourself, than to post the question:
SQL> ed
Wrote file afiedt.buf
  1  BEGIN
  2     FOR REC IN 1..10
  3     LOOP
  4             EXIT WHEN REC =5;
  5             /*
  6             business logic
  7             */
  8                  dbms_output.put_line('Processing: '||rec);
  9     END LOOP;
10* END;
11  /
Processing: 1
Processing: 2
Processing: 3
Processing: 4
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
  1  BEGIN
  2     FOR REC IN 1..10
  3     LOOP
  4             /*
  5             business logic
  6             */
  7                  dbms_output.put_line('Processing: '||rec);
  8             EXIT WHEN REC =5;
  9     END LOOP;
10* END;
SQL> /
Processing: 1
Processing: 2
Processing: 3
Processing: 4
Processing: 5
PL/SQL procedure successfully completed.

Similar Messages

  • About exit condition in a loop

    I have this loop,
    loop
       exit when months_between(sysdate,cur_st)<0;
    end loop;is it possible i can modify the exit condition by adding a OR keyword into it?:
    e.g.exit when months_between(sysdate,cur_st)<0 OR dbms_random.value(0,1)=0thanks in advance

    Moreover, you can use LOOP ... IF... THEN exit; END IF; ... END LOOP or WHILE... LOOP...END LOOP
    A try has never been wrong indeed.
    Nicolas.
    Message was edited by:
    N. Gasparotto

  • How to exit from a loop on 2 different conditions

    Hello Experts
    I’m trying to write a procedure in which I’m taking PROVINCE as an input parameter. All the provinces are stores in a table. I’m using a cursor and rowtype variable to check the province. After I finds province I displays province and its code. Everything works fine expect when I don’t find the province. I’m not sure how to exit from loop if I don’t find the province. I already uses exit when condition. I was expecting else condition should work and should exit from the loop but it doesn’t. Can please somebody show me how to exit if I don’t find province in the table through cursor.
    Here is my code
    set serveroutput on
    variable G_TAX varchar2(10)
    CREATE OR REPLACE PROCEDURE p_create(i_state VARCHAR2)is
    CURSOR cur_bb_tax is
    select * from bb_tax;
    bb_tax_details bb_tax%rowtype;
    begin
    if not cur_bb_tax%isopen then
    open cur_bb_tax;
    end if;
    loop
    fetch cur_bb_tax into bb_tax_details;
    if (bb_tax_details.state = i_state) then
    dbms_output.put_line(bb_tax_details.state || bb_tax_details.idstate);
    end if;
    exit when bb_tax_details.state = i_state;
    end loop;
    close cur_bb_tax;
    exception
    when others then
    dbms_output.put_line(SQLERRM);
    end;
    Thanks in advance

    Hello,
    Why don't you use dbms_output.Put_line and print output to find why logic is not able to execute? Maybe upper case/lower case/whitespace. *Also put your code between \ to preserve formatting*.
    Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Stopping output tasks properly before exiting a For-loop

    Hi,
    I've been having some trouble exiting a For-loop conditionally. The problem is that when the loop is stopped conditionally (a button is pressed) the DAQ (NI USB 6353) outputs get stuck to whatever value they were in. I tried stopping the DAQ Assistant output task (1 sample on demand)  before exiting the loop but that didn't solve the problem. Should this perhaps be done one iteration before exiting the loop or can it be done in the same iteration round?
    What would be the "right" way to exit a for loop with output tasks so that the output signals would be 0V after exiting? I know that I could "force" feed the DAQ Assistant with 0V control before exiting but in this case that would be quite difficult...
    Any ideas? Help is appriciated.

    Yes, I get it... However at this point I don't think that's an option.
    Would this kind of solution work? ( I am not able to test all possible solutions in the real system which is why I would like to get a confirmation first)
    The idea is to connect the output of the "Or" port to the "Stop" -ports of the DAQ Assistants in the loop.
    Edit. Will the output automatically go to 0V if I just stop the task? I am not really sure about this.
    Thank you.
    Attachments:
    exit-loop.jpg ‏8 KB

  • How to exit from the loop

    loop at itab.
    if <CONDITION>
    <EXIT LOOP>
    endif
    endloop.
    this ths condition , pz tel how to exit from loop

    Hi
    Loop
       statements
    EXIT
    Endloop.
    Will comes out of the loop.
    Regards,
    Sreeram Kumar.Madisetty

  • Which system variable is reset at the exit of a loop of an internal table

    which system variable is reset at the exit of a loop of an internal table
    a)sy-loop b)sy-index c)sy-dbcnt d)sy-tabix

    You might want to revist your threads from Friday, and award points and mark as "Answered" or "Solved".
    Regards,
    Rich Heilman

  • How to terminate or exit a for loop when the user clicks on stop button

    Actually my problem is to stop a loop when i click on stop button.
    example:i have two buttons 'start' and 'stop'
    in start buttom i wrote a for loop as
    dim i as integer
    For i=1 To 100000
    print i
    Next
    when i click on start buuton it prints 'i' value up tp 100000.
    my question is when i click on 'Stop' button the for loop has to terminate or Exit from the  loop and should stops the execution.
    Is it possible to termianate or Exit the 'for loop'
    PS.Shakeer Hussain
    Hyderabad

    I am unable to stop the loop and application not at all allowing to Press the Stop button.
    It seems like Hung, any advise ?
    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
            btnStop.Enabled = True
            btnSelectFile.Enabled = False
            btnStart.Enabled = False
            btnStop.Focus()
            Dim strFileName As String = txtFileName.Text.ToString
            Dim strLineText As String
            If System.IO.File.Exists(strFileName) = True Then
                Dim objReader As New System.IO.StreamReader(strFileName)
                While objReader.Peek() <> -1 And stopclick = False
                    strLineText = objReader.ReadLine()
                    MsgBox(strLineText, MsgBoxStyle.Information)
                    Application.DoEvents()
                    Thread.Sleep(My.Settings("strDelay") * 1000)
                    'System.Diagnostics.Process.Start(My.Settings("strFireFoxLocation"), strLineText)
                End While
            End If
        End Sub
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            stopclick = True
            btnSelectFile.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        End Sub
    Raman Katwal
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Check condition in Loop step in BPM

    Hi All,
      Need urgent help... I have to specify the condition in loop in such away I need to receive and bundle IDOC1 till I get IDOC2.  Please let me know how to specify the condtion in loop.
    Thank you in advance
    Regards,
    Dhill.

    HI
    See the below link
    /people/pooja.pandey/blog/2005/07/27/idocs-multiple-types-collection-in-bpm - Collection of IDoc to Single File
    /people/michal.krawczyk2/blog/2005/12/04/xi-idoc-bundling--the-trick-with-the-occurance-change - IDOC bundling
    Also we have Collection of messages based on the message a pattern in SAP BASIS see the BpmPatternCollectMessage and check for correct IP config..
    Regards
    Chilla

  • Condition in loop

    Hi Experts,
    I have a procedure, in which has a for loop.
    for ... loop
    end loop;
    I need
    for ... loop
    ( check the condition for each and every value. if the condition satisfies I need to update the flag. I don't want to update the flag each time.) ---> this is an extra condition.
    end loop;
    the for loop has to run for each every value.
    Suggestions please.

    940443 wrote:
    Hi Experts,
    I have a procedure, in which has a for loop.
    for ... loop
    end loop;
    I need
    for ... loop
    ( check the condition for each and every value. if the condition satisfies I need to update the flag. I don't want to update the flag each time.) ---> this is an extra condition.
    end loop;
    the for loop has to run for each every value.
    Suggestions please.
    Depends on your version, which you should always mention when posting.
    If you're on a recent version, look at the CONTINUE statement in the documentation, easily available on line.
    Cheers,

  • Exiting a server loop

    hi guys,
    does anyone know the correct way to exit a server loop, at the moment i have ....
    while(!SrvInput.getEndProgStatus()){          
    sk = skt.accept();
    System.out.println("Accepting new client connection");
    serverThread st = new serverThread(sk, conn);
    st.start();
    this just loops around creating a new thread for every client that connects, i have a class SrvInput which reads input from the console so if the user types "quit" the end prog status flag is set to true and the server exits.
    the problem is that for it to exit i need one more person to connect since it blocks on the accept call.
    Does anyone know how i can sort this out
    thanks for any help

    Hi.
    I'm trying to solve the same problem. I solve it, sending myself a Socket conection and then existing the while code like this:
        public void run()
            while (!isFinish())
                try
                    System.out.println("Waiting for connections.");
                    Socket client = serverSocket.accept();
                    if (!isFinish())
                        System.out.println("Accepted a connection from: "+client.getInetAddress());
                        LocationThread connect = new LocationThread(client);
                }catch(Exception e)
                    System.out.println(e.getMessage());
                    e.printStackTrace();
            try
                System.out.println("Server exiting");
                join(); // remove  join(), this a test.....
                serverSocket.close();
                System.out.println("Server has exit");
            }catch(Exception e)
                System.out.println("Error al cerrar el Socket");
        }This code belongs to the server side.
    I do this, in a Button in a GUI interface.
            try{
                location.setFinish(true);
                Socket s = new Socket(InetAddress.getLocalHost(),Integer.parseInt(result));
            }catch(Exception e)
                System.out.println("Error al tratar de terminar el servidor");
            }But I have a problem, I want my server to wait for their childs to finish, How can I do it?.
    a Join() , do the server to hang.
    Any suggestion ?.

  • JSF conditions and loop

    Dear programmer
    I'm new to JSF. I have almost finished to read all the tutorial and there is something that bothere me. In all the the examples, there is no use of condiion statements (if) or loops (for, while). How is it possible to program without them?
    I guess that with renderer I can do things that I could do with if statement and with UIData component I can create loop, but is it enough? It seems very odd to me that there are no conditions or loops.
    (Or maybe there are and I just not aware to it)
    For example I have a frame that is compounded from 2 forms. The first enable to user to search something. The second shows the results. I don't want the form of the results to be shown if there are no results. Can it be done with renderer?
    In order to show the results I need a loop. Is UIData enough?

    I have a frame that is compounded from 2
    forms. The first enable to user to search something.
    The second shows the results. I don't want the form
    of the results to be shown if there are no results.
    Can it be done with renderer?
    In order to show the results I need a loop. Is UIData
    enough?rendered="#{myBackBean.resultsAvailable}"
    You should have had more extensive JSF tutorial or an introductory book.
    I recommend Hans Bergsten's JavaServer Faces from O'Reilly, in which you could see
    many example code for conditionals and loops without using 'if', 'while' nor 'for'.

  • How to EXIT the while loop in Event response section?

    I'm writing a program to grab image using a NI card. The application uses the Event structure. When the GRAB button was pressed, it snaps image continually by putting the SNAP function in a while loop. Is there some way to exit the while loop?(Note :The while loop was put in the GRAB IMAGE event response section.)

    edit this event-case AND uncheck "lock front panel until the event case for this event completes".
    BTW, your thanks should go to Ankita, <a href='http://forums.ni.com/ni/board/message?board.id=170&message.id=151282'>here</a>
    cheers! 
    Message Edited by Dynamik on 11-13-2005 01:26 AM
    Message Edited by Dynamik on 11-13-2005 01:38 AM
    When they give imbeciles handicap-parking, I won't have so far to walk!
    Attachments:
    untitled.GIF ‏20 KB

  • Exit while in loop

    hie guys
    i am looping at two internal tables and want to exit through an if statement when a condition specified is not met however the code exits both loops.
    loop at itab1.
    loop at itab2.
    if itab2-value eq 0.
    exit.
    else.
    process.
    endif.
    endloop.
    endloop.
    however its not behaving as such..i have tryed to use return statement but it still wont work. i have verified my entries and the conditions exist to be true for some entries ie itab2-value ne 0 but the program exists. please assist.
    regards.
    Isaac Prince

    YOU CAN USE IT
    BUT THE SECOND TABLA MUS BE SORTED
    LOOP AT T_DOCTOS_WORK.
        T_DOCTOS_FINAL-BELNR_PAGO = T_DOCTOS_WORK-BELNR.
        T_DOCTOS_FINAL-BUDAT_CONCILIA = T_DOCTOS_WORK-AUGDT.
        T_DOCTOS_FINAL-BUDAT_PAGO = T_DOCTOS_WORK-BUDAT.
    Se tratan las partidad del proveedor
        READ TABLE T_DOC_BSIK_BSAK WITH KEY
            AUGGJ = T_DOCTOS_WORK-GJAHR
            AUGBL = T_DOCTOS_WORK-BELNR
            BINARY SEARCH.
        IF SY-SUBRC EQ 0.
          INDEXK = SY-TABIX.
          DO .
            READ TABLE T_DOC_BSIK_BSAK  INDEX INDEXK.
            IF T_DOC_BSIK_BSAK-AUGGJ NE T_DOCTOS_WORK-GJAHR OR
               T_DOC_BSIK_BSAK-AUGBL NE T_DOCTOS_WORK-BELNR OR
                SY-SUBRC NE 0.
              EXIT.
            ELSE.
              INDEXK = INDEXK + 1.
    *MAKE YOUR CODE
    ENDIF.
    ENDDO.
    ENDIF.
    ENDLOOP

  • Exiting from Inner Loop.

    Example.
    Loop at I_catsdb.
    Loop at I_catsdb_tmp.
    endloop.
    endloop.
    How do I come out of the inner loop on certain conditions?

    Hi,
    Use the EXIT statement..
    Loop at I_catsdb.
    Loop at I_catsdb_tmp.
    Check the conditions..
      EXIT. 
    endloop.
    endloop.
    Thanks,
    Naren

  • About condition for loop in BPM

    I design a loop, condition is counter<>3.
    It seems only receives 3 messages when I send more than 3.
    for example, I send 105 messages, for every 10 messages it will generate a file. and I totally have 11 files.
    What is the best way to end the loop?

    Hey,
           you need to have two loops in this.
           Have your send step(for the file) in the inner loop.
            The condition for this loop will be te number of messages that you need per file.
          The outer loop should terminate when all the messages are recieved.(recieve step will be in the outer loop)
       This is not possible with the no. of messages
    You can do one thing, provide a stop message as an input along with the other messages.
    And set the condition for the outer loop for the stop message.
    This will terminate the outer loop.
    regards,
            Milan

Maybe you are looking for

  • How to use one boolean button to control many boolean buttons?

    I would like to create a LabView control interface with boolean buttons. As my attachment picture shown, there are four boolean buttons. The button1 is the main power, if I press ON button1, other three buttons also turned to ON at the same time. How

  • Message in Clock-In/out Correction

    Hello everybody. Some times when a user make a time correction using the clock in/out iView he/she gets a message when he/she reviews the correction. The message is in Spanish: "Lista de mensajes no se puede actualizar de momento por motivos técnicos

  • Solaris 10 x86 is impressive but needs more h/w support

    I know what you're thinking, another hardware support gripe. :) First of all, I'd like to say that despite not being able to use my network card, view DVDs, use my sound card or laser printer with Solaris 10, I am extremely impressed with the profess

  • Weblogic 12c on windows 2003(32bit)

    Hi guys, I installed weblogic 12c on windows 2003(32bit)(oepe-indigo-installer-12.1.1.0.1.201203120349-12.1.1-win32.exe); I created schedule job (startup weblogic console on server startup); The  weblogic instance run java applications; Every second

  • *.air files not working on android honeycomb

    hello friends, i've android tablet(honeycomb 3.2) and adobe air installed with latest version. i have file with air and extension is also .air however when i tried to open file it returns an error like 'there is no application found to open this file