Newcomer to Java.. how to end a loop?

hi,
what is the difference between:
return;
break; and
continue;
?

It should also be noted (if it hasnt) that you can LABEL loops
and break out of specific loops by name.
http://www.devx.com/tips/Tip/31853
X:
for (int i = 0; i < x; i++) {
   Y:
   for (int j = 0; j < y; j++) {
      Z:
      for (int k = 0; k < z; k++) {
         if (some_condition) {
            break Y;
}

Similar Messages

  • How to end consumer loop

    I am using producer/ consumer pattern to separate data acquistion and processing. The consumer loop is much slower than the producer loop. If I put "release queue" outside of the producer loop to stop the consumer loop, the consumer loop can just run once. But I need consumer loop to run same times as producer loop. So I did not use the release queue to stop the consumer loop but used the error connecting with  "stop if true" in the consumer loop. The producer loop and consumer loop are in a sequence structure. It seems that the sequence contains producer/consumer loops can never finish to enter into the next sequence. I think that producer loop and consumer loop have all stopped because their iteration numbers stop increasing at certain time. But the vi can never go into the next sequence. So I am very confused about that. If I put "release queue" outside of the producer loop to stop the consumer loop, the vi can finish this sequence and go into the next sequence. Do anyone know how to solve the problem?

    Sophia,
    The idea of passing the stop command via the queue is that it will be at the end of the queue - after all the data.  The consumer loop will see the stop command after it processes all the earlier data. In this case it might be better called "End of Data" rather than "Stop." 
    The sequence structure is totally unnecessary.  Use dataflow to handle the initialization and  completion code.  The sequence structure will definitely proceed to the next frame when all the code within the current frame completes execution.  If the iteration counts have stopped increasing it may mean that the loops have stopped running or that the producer is blocked, waiting for something within it to finish so it can go to the next iteration.  It is also possible that the consumer loop has started an iteration but no data is in the queue.  Since the timeout is default at -1 the Dequeue will wait forever for data.
    Please look at the style guides.  Use left to right wiring and avoid hiding wires behind other objects.  Also try to keep the diagram to the size of one screen.
    Parallel loops should always have some kind of wait or delay to allow CPU resource sharing.  In the producer loop the data acquisition VI may provide that function.  In the consumer loop the easiest way to get a delay would be to change the Dequeue wait time to something other than -1.  You also should check the Dequeue Timed out? line if you use timeout for the delay.  If it is true, then the data is not valid and should not be analyzed in the for loop.
    You probably only see the last of the 10 spectra. Unless the datasets are rather large, the loop will probably run too fast to see the others.
    Lynn 

  • Ending Java War game with while loop

    How would i go about ending a java war game witha while loop. I want the program to run until all of the values of one of the arrays of one of the players split decks has all null values.

    GameObject[] theArrayInQuestion;
    // populate array somehow or other
    void methodWithLoop() {
       while(arrayNotNull(theArrayInQuestion)) {
       // do stuff
    boolean arrayNotNull(Object[] array) {
      int len = array.length;
      for(int i = 0; i < len; i++) {
        if ( array[i] != null ) {
          return true;
      return false
    }

  • How to start AND end a loop using a Boolean Button set to "Switch When Released" operation

    I have a Boolean button set to "Switch When Released" operation. When I press this button (now it's in the On state) I want to run a loop that does something continupously (for now, let's say it displays a simulated sine wave) until I press the button again (now the button is in the Off state) in which case, I want to end the loop. I am wiring my button to the loop condition that's set to "Continue if true" and have a "Wait Until Next ms Multiple" of 200 ms (I tried up to 500 ms). When I run the VI and press the button the first time, I see the sine wave displayed. But when I press the button again, nothing happens. It looks like it does not respond to the user interface. What's happening. What am I doing wrong? I'm using an Event Handler design pattern. I've also tried the Producer/Consumer (Events) design pattern. But I don't imagine the particular design pattern should make a difference. I've attached my code. Thanx.
    Fataneh
    Attachments:
    My_Event_Handler.vi ‏107 KB

    A simple solution would be to harness the timeout event, where you would put your data simulation. No need for parallel loops and local variables.
    The event timeout is starts out as  -1 (infinite) but pressing the start/stop button toggles between a 200ms and an infinite timout whenever it is pressed. Since the evet structure always runs, all other events (e.g. stop) are also serviced.
    Please ask if anything is not clear... Good luck!
    Message Edited by altenbach on 07-13-2005 04:20 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    My_Event_HandlerMOD_CA.vi ‏116 KB

  • How to resolve the loop in universe level

    how to resolve the loop in universe level

    Hi, Kashim
              In univese level loops resolved by Chasm Trap and Fan Trap methods.
    Chasm Trap:  A chasm trap is a type of join path between three tables when two many-to-one joins converge on single table, and there is no context in place that separate the converging join paths.
    There is "many-to-one-to-many"relationship beween the three tables in the universe structure.you can define a context for each table at the many end of the joins.
    A chasm trap is not dependent on the object types, the query could be made up of only dimensions,only details,or only measures,or any combination of the three types with the "many " tables for chasm to occure.
    you can also detect the chasm trap Automatically, tool---->Detect context
    To resolve the chasm trap, you need to make two separate Queries and than combine the results Depending on type of objects defined for the fact tables and the type of end user environment,
    Fan trap: it is occured when there is a "one-to-many" join to the table that "fans out " into another "one-to-many" join to another table.
    Avoid fan trap: The first place by relating all measure objects in the universe to the same table in the universe structure,Avoid placing a measure on anything other than the last table in a in a table path, which is the table with the "many" cardinality attached to it.
    This methods is not recomended as it only works for measure objects and may result in inefficienies in processing the query. This resolution works the same for chasm and fan traps.
    you can create more alias tables based on your requirement in single universe. and it is true conext, when two or more paths.
    Theese methods also apply for resolving loops:
    Short cut join also one method for resolving loops
    Aggregate aware function used another waty for resolving loops
    if you are not resolving the loop result is  redusing the number of records.

  • How to end a procedure immediately

    How to end a procedure immediately before it is ended normally when some exceptions that I can't anticipate occur.

    If you want to stop the process, you have to propagate the exception through your PL/SQL blocks.
    Let's see this 2 examples :
    SQL> Declare
      2    ln$result number ;
      3    procedure p1 ( pn$input IN NUMBER )
      4    is
      5      ln$i pls_integer := 10 ;
      6    Begin
      7      ln$result := ln$i / pn$input ;
      8    Exception
      9      when zero_divide then
    10      dbms_output.put_line('** value error with : ' || pn$input ) ;
    11    End ;
    12  Begin
    13    For i In -5 .. 5 loop   
    14      p1(i) ;
    15   dbms_output.put_line( 'calulation for ' || i || ' = ' || ln$result ) ;
    16    end loop;
    17  Exception
    18    when others then
    19      dbms_output.put_line( 'stop with error : ' || sqlcode ) ;
    20  End;
    21  /
    calulation for -5 = -2
    calulation for -4 = -2,5
    calulation for -3 = -3,33333333333333333333333333333333333333
    calulation for -2 = -5
    calulation for -1 = -10
    ** value error with : 0
    calulation for 0 = -10
    calulation for 1 = 10
    calulation for 2 = 5
    calulation for 3 = 3,33333333333333333333333333333333333333
    calulation for 4 = 2,5
    calulation for 5 = 2
    PL/SQL procedure successfully completed.the main procedure is not stopped by the exception
    let's propagate the excexption from the p1 procedure (line 11) :
    SQL> Declare
      2    ln$result number ;
      3    procedure p1 ( pn$input IN NUMBER )
      4    is
      5      ln$i pls_integer := 10 ;
      6    Begin
      7      ln$result := ln$i / pn$input ;
      8    Exception
      9      when zero_divide then
    10      dbms_output.put_line('** value error with : ' || pn$input ) ;
    11      raise ; -- propagate the exception
    12    End ;
    13  Begin
    14    For i In -5 .. 5 loop   
    15      p1(i) ;
    16   dbms_output.put_line( 'calulation for ' || i || ' = ' || ln$result ) ;
    17    end loop;
    18  Exception
    19    when others then
    20      dbms_output.put_line( 'stop with error : ' || sqlcode ) ;
    21  End;
    22  /
    calulation for -5 = -2
    calulation for -4 = -2,5
    calulation for -3 = -3,33333333333333333333333333333333333333
    calulation for -2 = -5
    calulation for -1 = -10
    ** value error with : 0
    stop with error : -1476
    PL/SQL procedure successfully completed.Francois

  • Deitel, Java How To Program exercise question

    Hi, :)
    I'm new to programming and I'm using the Java How To Program Fourth Edition from Deitel and Deitel as my text. I've run into a problem with Exercise 2.16 Where I'm asked:
    "Write an application that asks the user to enter two numbers, obtains the numbers from the user and prints the sum, product, difference, and quotient of the numbers."
    From that I have written this code:
    // Exercise 2.16
    /* An application that asks the user to enter two numbers, obtains the numbers from the use and prints the sum,
    product, difference and quotient of the numbers. Using the techniques shown in Fig 2.9 */
    //Java extension packages
    import javax.swing.JOptionPane;
    public class Exercise2_16{
         //Main method
         public static void main(String args[]){
         String firstNumber, secondNumber;                          //introduce variables
         int number1, number2, sum, product, difference, quotient;          //introduce variables
         firstNumber=JOptionPane.showInputDialog("Enter first integer:");     //Create input window
         secondNumber=JOptionPane.showInputDialog("Enter second integer:");     //Create input window
         number1=Integer.parseInt(firstNumber);                         //String to integer
         number2=Integer.parseInt(secondNumber);                         //String to integer
         //perform operations
         sum = number1+number2;
         product = number1*number2;
         difference = number1-number2;
         quotient = number1/number2;
         //Display results
         JOptionPane.showMessageDialog(null, "The sum is " + sum,
         "The product is " + product, "The difference is " + difference,
         "The quotient is " + quotient, "Results", JOptionPane.INFORMATION_MESSAGE);
         //End program
         System.exit(0);
         }//End main method
    }//end class Exercise2_16
    When I compile this code I get an error and I can't figure out why. Any help is really appreciated as I'm stumped and given the simplicity of the app I'm kinda bummed it has me stuck :(.

    I substituted your line and this is the error I'm receiving now:
    F:\jdk1.3\Learning Java>javac Exercise2_16.java
    Exercise2_16.java:32: unclosed string literal
    JOptionPane.showMessageDialog(null, "The sum is " + sum + ", The product is" + product + ",
    The difference is" + difference + ", The quotient is" + quotient + ", \"Results\", JOptionPane.INFORMATION_MESSAGE);
    ^
    Exercise2_16.java:35: ')' expected
    System.exit(0);
    ^
    2 errors
    It doesn't really matter to me if there are returns but maybe for readability there should be and so I learn how to as well.

  • End of loop in FindFirst

    Hello everybody,
    I should be very interested to know if anybody has already seen such messages.
    When I launch a FindFirst on an OraDynaset, I see a message with "End of Loop" as a title, and in the text :
    Ins: 1, BS: 0, BV:0 VS:1
    and an OK button.
    When validating, following messages run :
    Ins: 2, BS: 0, BV:0 VS: 2
    Ins: 3, BS: 1, BV:0 VS: 0
    Ins: 4, BS: 1, BV:0 VS: 1
    Ins: 5, BS: 1, BV:0 VS: 2
    Ins: 6, BS: 2, BV:0 VS: 0
    until 8, then an error -2147417848 (=hexa 80010108)
    the invoked object has disconnected from its clients.
    I do not remember I placed such messages in my code, anyway I did not find "Ins" in my modules, except for the Instr function. So, maybe this is something Oracle coded ?
    Does that recall anything to anybody ?
    I could obtain that after repairing Ms-Office, before that I only obtained the message telling that "Excel has met a problem and must close, we are sorry about ..."
    Then I saw that objects had a tendancy to disconnect, and I could resume the code after reconnecting them in the execution window.
    I am going to report presumed net micro-cuts to the support, but this does not give me the meaning of the messages I read, nor tell me what I must do.
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    Microsoft Office Excel 2003 (11.8033.8107) SP2
    ODBC 3.525.1117.0

    Hi
    MOVE 'TOP_OF_PAGE' TO ls1_events-form.
    what is thie c_form_top_of_page instead write as above ,i hope it will work
    Regards
    Pavan

  • How to end text element in sap script

    how to end an text element in sap script
    this is the format.
    /E text element name
    &tablename-fieldname&
    text-text-text-text
    now if i do not end that text element it is not displayiny my below text , so what to do in this case

    Go through the links mentioned below.
    http://www.****************/Tutorials/Smartforms/SFMain.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3c5d9ae3-0501-0010-0090-bdfb2d458985
    http://www.sapmaterial.com/smartform_example.html
    Re: Hands on SAP Smart Forms
    smartforms
    Reward points if useful.

  • How to stop while loop when a specified function is terminated?

    I want to make a program which has 2 thread, one of which is to control some devices, and the other is to measure outputs of the devices.
    To do that, I should make a 2 independent loops, but there comes a problem here.
    I want to terminate 2 loops at the same time, but it's difficult for me to do that, because when I try to notify upper sequence's termination to lower loop by some value change, they have some dependency.
    That's why I need your help. I want to know how to stop lower loop when the upper sequence's termination keeping their independency.
    Please let me know. Thank you.
    Attachments:
    help.JPG ‏200 KB

    Is the upper loop commanding the lower loop at all?  I would think you would have some type of communication between the loops.  Just use that communication to send a stop command.  Or the next best way is to just simply use a notifier.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Highlighted button Disappearing at the end of loop?

    Hey guys,
    I have a simple menu with a few buttons and a short clip in a drop zone and a song in the background. All of this takes a minute to reach the end and once it reaches the end it loops but after the loop the highlight is gone and the buttons wont work ( on a DVD player).
    Any suggestions will be appreciated.
    Cheers,
    Alex

    The main problem is
    var fileList = inputFolder.getFiles();
    You are getting a list of all files and folders that exist in that folder, they could be text files etc.
    It is better to specify the file types IE:
    var fileList = inputFolder.getFiles(/\.(jpg|tif||psd|)$/i);
    As this will only get a list of files that are jpg, tif or psd

  • How to set a loop on an .flv so that an exported .swf loops?

    hi there. i am using Flash CS4 and I would like to know how to set a loop in an flv file so that when it is exported to swf, the movie will loop. Basically i have taken an existing interactive flash movie and have decompiled it into its individual flv counterparts. what i intend to do is take out all the nonsense from each flv file and then reconstruct the flash movie, export each file to swf and then convert each swf to avi or some other video format. to do this i will be using sothink swf to avi converter which allows you to convert swf files to avi files. this program allows you to convert swf files that loop by looping the swf file for as long as you want until you stop it, in which a video file is created from "the recording"
    after i decompiled the original file, many of the existing flv files were already set to loop. i know this because when exported to swf the swf file would loop. now when i went ahead and went into each flv file to edit a couple things, when i went to export them to swf, the swf files wouldn't loop. mind you, some of them did loop, and some of them did not loop. the ones i have edited are all supposed to loop and i cannot figure out what it is thats preventing some of the flv or exported swf files to loop. all i did was take out a few unnecessary frames from the beginning of each flv and nothing more. i am pretty new to Flash and do not know anything about coding and know very little about flash settings.
    i figured that selecting the "loop playback" option in the control drop down menu might help seeing as the flv file does loop when played in the editor, but again when exported to swf the swf file does not loop. what confuses me the most is that some of the exported swf files do loop. ALL of the exported swf files need to loop and my guess is that in order to make that happen, something in the flv file needs to be set correctly.
    can someone please assist me with this issue? if there is a way to simply loop an existing swf file that does not loop, can someone tell me how to do that? any help with this problem is greatly appreciated and i appologize if something like this has been asked before.... i just couldnt stand looking through 22 pages of search results to find the exact solution to my problem
    thank you!!!

    Hi,
    You can use shortDesc property. Something like
    <af:commandToolbarButton text="Some Button"
          id="ctb1" shortDesc="This button does something.."/>-Arun

  • How to end a work item exlicitly without executing it?

    i want to find out how to end a workitem explicitly without executing it from the business workplace. we have created a dummy workitem and would like to end it when it is not needed.
    i have set up the terminating event in the workitem task but even though the event is raised the workitem is not ended and the workitem is still in the inbox. i was expecting that when the event is raised the event will end the workitem and it will move into the outbox.
    am i doing something worng? why isnt the workitem getting ended and move to outbox when the terminating event is raised?

    Hi Arghadip,
    thanks for your inputs. That was really useful but in my case i dont have the workitem ID. Actually here is my process, the system creates a workflow when a invoice is created and it is blocked for payment. When the invoice triggers a workflow it does two things in a FORK. One it sends an email and the second it sends a workitem. The workitem is a dummy workitem. When the user reply's to the email a RFC FM is called from the external system which will release the invoice in SAP. Now once this is done we would like to close the workitem which is lying in the business workplace. So i have implemented the terminating event however i guess that doesnt work. When the RFC FM is called externally it releases the Invoice using a BAPI and once it is done i am calling the FM SWE_EVENT_CREATE to raise the event to terminate the event.
    Am i doing something wrong?

  • How to end RDP sessions remotely from different network?

    Hi
    How to end RDP sessions remotely for windows 2008r2 server from different network?
    not from local LAN
    Thanks

    Hi
    what ports need to be open to successfully connect to server behind firewall?
    from WAN to LAN using :
    net use \\servername_or_IP /USER:username “password“
    or
    qwinsta /server:ServerIP
    Thanks

  • Subtle bug in Deitel & Deitel "Java How to Program" book

    Merry x mas and happy new year, guys.
    I have this applet (which is at the same time runnable and listener) its printed in Deitel & Deitel "Java How to Program" book 3rd ed.
    The program works but as you turn on and off the "suspend" checkboxes some of the threads are not notified, so they go to infinite wait state, deadlock. I couldn't figure out what is wrong or how to fix the problem.. please read the code below, or copy and paste this code to your eclipse, its just one file, then play with the check boxes, some of the threads don't wake up after wait... technically they don't shift from WAITING to TIMED_WAITING state.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * @author
    // Fig. 15.7: RandomCharacters.java
    // Demonstrating the Runnableinterface
    public class RandomCharacters extends JApplet implements Runnable, ActionListener {
        private String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        private JLabel outputs[];
        private JCheckBox checkboxes[];
        private final static int SIZE = 3;
        private Thread threads[];
        private boolean suspended[];
        public void init() {
            outputs = new JLabel[SIZE];
            checkboxes = new JCheckBox[SIZE];
            threads = new Thread[SIZE];
            suspended = new boolean[SIZE];
            Container c = getContentPane();
            c.setLayout(new GridLayout(SIZE, 2, 5, 5));
            for (int i = 0; i < SIZE; i++) {
                outputs[i] = new JLabel();
                outputs.setBackground(Color.green);
    outputs[i].setOpaque(true);
    c.add(outputs[i]);
    checkboxes[i] = new JCheckBox("Suspended");
    checkboxes[i].addActionListener(this);
    c.add(checkboxes[i]);
    public void start() {
    // create threads and start every time start is called
    for (int i = 0; i < threads.length; i++) {
    threads[i] = new Thread(this, "Thread " + (i + 1));
    threads[i].start();
    public void run() {
    Thread currentThread = Thread.currentThread();
    int index = getIndex(currentThread);
    char displayChar;
    while (threads[index] == currentThread) {
    // sleep from 0 to 1 second
    try {
    Thread.sleep((int) (Math.random() * 1000));
    synchronized (this) {
    while (suspended[index]
    && threads[index] == currentThread) {
    wait();
    } catch (InterruptedException e) {
    System.err.println("sleep interrupted");
    displayChar = alphabet.charAt(
    (int) (Math.random() * 26));
    outputs[index].setText(currentThread.getName() + ": " + displayChar);
    System.err.println(currentThread.getName() + " terminating");
    private int getIndex(Thread current) {
    for (int i = 0; i < threads.length; i++) {
    if (current == threads[i]) {
    return i;
    return -1;
    public synchronized void stop() {
    // stop threads every time stop is called
    // as the user browses another Web page
    for (int i = 0; i < threads.length; i++) {
    threads[i] = null;
    notifyAll();
    public synchronized void actionPerformed(ActionEvent e) {
    for (int i = 0; i < checkboxes.length; i++) {
    if (e.getSource() == checkboxes[i]) {
    suspended[i] = !suspended[i];
    outputs[i].setBackground(
    !suspended[i] ? Color.green : Color.red);
    if (!suspended[i]) {
    notify();
    return;
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Abiel wrote:
    No, notifyAll() is used to tell the threads that we're stopping.... see that it's written in the stop() method of the applet. Eg if the user browses away from our applet we set the array of threads to null and notify them all. So notifyAll() makes sense.Yes, it does make sense there too (!!!!!!!).
    However, I gave it a try with what u suggested, and it didn't work (as expected) .... Apparently you did not really read my suggestion or my explanation. If you had, you'd have expected it to work and it would have worked.
    the problems still remains, some threads are getting in wait state even if their check box is not suspended.Maybe you should add the following code to understand the root cause and solution.
        System.out.println("Thread " + index + " will wait to be notified.");
        wait();
        System.out.println("Thread " + index + " was notified.");
    what could the problem be?Improper use of notify()
    With kind regards
    Ben

Maybe you are looking for

  • How to I center a dialog box in the screen?

    Simple question, and I hope a simple answer. I need to center various sized dialog boxes in the screen. I've tried getcenterpoint(), but I don't know EXACTLY how to use it.

  • OS 10.5.4 and Appleworks Database

    I just purchased a new iMac 24 inch. I also have a bunch of old databases from Appleworks 6. Can I install Appleworks on the new iMac so I can use the older databases? I didn't realize iWorks wouldn't have a database application. If I can't install A

  • Issue in adding up columns.

    Hi: Does anybody know how to do this in Query Designer: I have a Calculated KFig. in a Column and is not bringing me the addition of the partial values in the result row. Is calculating again the formula, and thus delivering a wrong result. How can I

  • Extended XSD's and Oracle business rules in SOA

    I have extended an XSD to add new elements within a complex object but when I use these within Business rules I receive the following error [10:10:58 AM] Invalid logging line: #;There was an error deploying the composite on SOAAdminServer: Deployment

  • Agent push issues on Server 2012 targets - any known gotya's

    Hi, I'm having ongoing issues which I believe are directly firewall related when pushing agent to Windows Server 2012 R2 computers. I get the usual RPC unavailable errors and the workaround I use is I have to turn of the firewall via control panel (s