How to Stop an infinite loop

I'm reading from the keyboard. I take the input and use it as a while statement's condition. However, I can't break out of the loop once i'm in it. I've tried everything, but nothing works. The loop should terminate after null is returned, but it doesn't. Here is my code:
inputline = keyboard.readLine();//read the keyboard
while( inputline = keyboard.readLine() )!= null){
inputline = keyboard.readLine();//read the keyboard
System.out.println(" i'm in the loop");
DiskOut.println( inputline );
DiskOut.flush();
inputline = keyboard.readLine();//read the keyboard again
}//end while
Also, I have tried this while statement
while( inputline =="\n" || inputline == "\r" || inputline == null)
please help!!

Your code won't even compile. The part between "while" and "{"
has too many right-parentheses.
What are "keyboard", "DiskOut", etc.? You'll probably need to provide
more details, plus the actual code you're trying to debug, before anybody can help you.
Assuming "inputline" is a String, then that alternative while expression wouldn't work anyway. You can't compare Strings with "==" (at least not in the way you probably mean).
The following code does something which seems to be roughly what you want:
import java.io.*;
public class Foo {
  public static void main(String[] argv) {
    try {
      BufferedReader foo = new BufferedReader(new InputStreamReader(System.in));
      String line;
      while((line = foo.readLine()) != null) {
        doSomething(line);
    } catch (IOException e) {
      e.printStackTrace();
  public static void doSomething(String it) {
    // do something here
}But note that the while loop doesn't end when someone inputs a blank line; it ends when the stream ends, which in this case is when someone inputs EOT (in unix systems, Control-D).
readLine() doesn't return null on blank lines.
If that's what you're looking for, then maybe you want to end your while loop when inputline.length() == 0.

Similar Messages

  • How do I stop an infinite loop because of a poorly placed user prompt during developmen​t without closing LabView?

    How do I stop an infinite loop because of a poorly placed user prompt during development without closing LabView?
    Thank you!
    Solved!
    Go to Solution.

    chuck72352 wrote:
    Here is an example of a VI that I can't stop.
    Epic Fail
    but seriously, as was suggested, download Darren's Abort.vi. It comes in very handy for these.
    Message Edited by Broken Arrow on 05-03-2010 01:06 PM
    Richard

  • How to create an infinite loop that cannot be cancelled?

    Hi , im new around java and i need a program that keeps on repeating after each each input/uses(generally meant for different user) and cannot either stop using "Cancel" or "x" while stopping only using the "stop" button
    I got a few lines of codes that look like this : String arg = "";
    do{
    JOptionPane.showInputDialog("hi");
    }while ( arg != "y" || arg!= "Y");
    and it cannot be stop with both cancel and"x"(which i wanted)
    but when i used this logic with
    Valid validUserInput = new Valid();
    do {
    userInput = validUserInput.validUserInput(a);
    switch(userInput){
    case 1 : validUserInput.optionOne(b);break;
    case 2 : validUserInput.optionTwo(c);break;
    case 3 : validUserInput.optionThree(d,e);break;
    default : validUserInput.validUserInput(f);
    }while(looping != "" || looping != " ");
    it does not really work(while it will keep looping, it can be easily stop by pressing cancelled or "x")
    So is there any logic or method that can prevent the program from being stop?
    Thankyou!

    elricscript wrote:
    "That is helpful. It gives him a direction where he can focus his research. Namely, 'how to run a program in kiosk mode' rather than 'how to create an infinite loop that cannot be cancelled.'"
    No... He already mentioned he wants to "e.g Interactive kiosk", so saying "properly kiosk it" isn't adding any new information. Rather it's just giving the person a dead point of: you're doing it wrong. Pointing out someone is wrong is not a positive enlightenment. Pointing someone in the right direction is more productive.
    >"That is helpful. It gives him a direction where he can focus his research. Namely, 'how to run a program in kiosk mode' rather than 'how to create an infinite loop that cannot be cancelled.'"
    No... He already mentioned he wants to "e.g Interactive kiosk", so saying "properly kiosk it" isn't adding any new information.
    Yes it is. He asked how to do it using some Swing trickery, and I said it won't work. Which is true. The OP didn't already know that, clearly, hence the question. Now he does. That's pretty much new information if you ask me.
    Rather it's just giving the person a dead point of: you're doing it wrong.Right. He is. However, the problem is now no longer related to Java, and not something I can help him with. You should try that: not answering questions you don't know the answer to. It's actually more helpful than posting misleading, wrong answers.
    Pointing out someone is wrong is not a positive enlightenment. I'm giving basic technical help, not yoga lessons.
    Pointing someone in the right direction is more productive.As already stated, I am as ignorant of how to make a Java application into a kiosk app as the OP is. What value can I add in light of that information? I began by answering a question that was not stated to be about kiosks. Once the question moved outside of my area of knowledge, I stopped trying to answer.
    I notice you're not giving him any help, being more interested in admonishing others as you are.

  • How to stop  after first loop operation  over?

    Hi friends.
    How to stop  after first loop operation  over?
    I have a loop operation in module pool program.
    After first loop over I want to stop.
    I used the STOP keyword, but it is going to dump.
    Thanking you.
    Regards,
    Subash

    Hey,
    The statement STOP is forbidden in methods and, since release 6.10, leads to an uncatchable expection during the processing of screens called with CALL SCREEN...
    As they said above, use a EXIT statement to fix this DUMP...
    Regards,
    Diogo Carvalho

  • How to stop a while loop in LabVIEW from a C program

    How to stop  a while loop in LabVIEW from a C code

    hi
    I think by creating dll you can stop the while loop from your C program.For that you just create dll (Dynamic Link Library) for the VI which has that while loop.
         Anyway can u please explain ur requirement clearly.

  • How to stop a while loop after certain time using Elapsed time vi

    how to stop a while loop after certain time using Elapsed time vi.

    Hi Frankie,
    Just place the Elapsed Time VI inside the WHILE loop, and wire the 'Time Has Elapsed' output to the conditional terminal in the lower right corner (which should be set to 'stop if true' by default).
    In the future, please post your LabVIEW questions to the LabVIEW Forum.  You have a much better chance of getting your questions answered sooner, and those answers can then help others who are searching the LabVIEW forums.  Thanks!
    Justin M
    National Instruments

  • Help on how to make an infinite loop with the same space on all images

    HI:
    I made a movie clip with infinite  loop in which there are images that move from right to left something simple like a marquee, and each image has a blank space between  them, but between last and first image there is a more space, how I can do to  make all images have an equal space between each one and that the motion never stops.

    Thanks for your time and answers my friend, but I'm still not be able to achieve what I want, I forgot to tell that I'm doing this by layers, let's say, I have 5 images, (in fact I have like 50 images converted to movie clip symbols) each image has it's own layer, layer 1, layer 2, layer 3, layer 4, layer 5, then I put a 200 frame motion tween on all layers at 30 fps, then I arranged layer 1 on the first frame to the frame 200, the second layer from frame 50 to frame 250, third layer from frame 100 to frame 300, fourth layer from frame 150 to frame 350, and fifth layer from frame 200 to frame 400, by this I mean I put a 50 frame of space on each image but if you can see, the last image has a duration from frame 200 to frame 400, and there's nothing on frame 250 where it is supposed to be another image to match the same blank space of all the others, the movie clip restarts on the frame 400, and there's a 150 frames of blank space between the last image and the first image, I put the gotoandplay on the frame 250, but it abruptly restarts the movie.
    Is there another way to do this ?
    Am I doing something wrong ?
    Please I really really need help on this.
    Thanks

  • How to stop a "for" loop

    Hello,
    Do you know how I can stop a for loop ? because when I click on the stop switch on my front panel, the VI don't stop and continue to run the loop.
    Peter.
    Labview 2010
    Solved!
    Go to Solution.

    Peter,
    It sounds like you need a while loop, not a for loop. A button or switch does not traditionally control iterations of execution for a for loop.
    Please post your code so we may help better.
    -Chazzmd

  • How to stop a while loop of event structure from a main vi

    Hello;
    sorry for my english
    I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
    any help please or example !!!   
    Solved!
    Go to Solution.
    Attachments:
    stop a while loop and event structure from main vi.png ‏16 KB

    IYED wrote:
    Hello;
    sorry for my english
    I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
    any help please or example !!!   
    If this is an example of how your code looks, I'd clean it up before the developer who has to work on it next hits you over the head with his LabVIEW Style Book. 
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • How to stop a while loop which contains a timed loop

    Hi,
    I'm a new hand to labview, and I'm using labviw 7.1, NOT 8.x.  I'm trying to do a measurement, in which the flow would look like the attached file (I have stipped all hardware related components to make it easy to read).  My questions are:
    1. In Loop 3, when the comparison (x>20.85) is true, Loop1, Loop2 and Loop3 are stopped, why it won't quit the while loop (I have wired it to  while loop stop)?
    2. When it is running, I click on stop button, why it won't stop?
    Thanks!
    Attachments:
    SyncTimedLoop32.vi ‏228 KB

    hwm wrote:
    2. When it is running, I click on stop button, why it won't stop?
    The stop button is read outside of the inner while loops.  So the inner while loops will continue to run until their stop conditions are met.
    hwm wrote:
    1. In Loop 3, when the comparison (x>20.85) is true, Loop1, Loop2 and Loop3 are stopped, why it won't quit the while loop (I have wired it to  while loop stop)?
    It seemed to me like it would, but sometimes it seemed like I had to set change the numeric value one more time before it would.  You have a very odd structure there by placing the event structre inside the while loop with the other loops.  I think you may be running into issues where events are getting queued up in the event structure, or race conditions between when the event structure might execute relative to the other loops.  It is all very odd and difficult to predict all the ways these structures might interact and relative timing.  Usually event structures would belong in their own parallel while loop.  I think you need to rethink exactly what you are trying to do here.  It probably isn't event necessary to use the stop timed structure functions.  A local variable or a notified to pass the "Stop status" from loop 3 to the other loops (or the separate event structure loop to the other 3) would probably be better.

  • How to stop a while loop when using tab control

    How do you use a tab contol to stop what is happening on one tab when you switch to another tab?  In the test example I attached, I have a while loop nested inside a case structure controlled by the tab control.  When I tab to page two the elapsed timer starts but when I switch to another tab it does not stop.  I can't come up with an easy way to stop or exit the while loop when I change tabs. 
    Thank you
    Danny
    Attachments:
    tab control.vi ‏24 KB

    I played with it a little more and came up with this fix.  This fixes it but is not tied to the changing tabs as I was looking for.  Is this just too many nested loops and a bad idea?
    Danny
    Attachments:
    tab control fix maybe.vi ‏26 KB

  • How to stop a while loop with long delay

    Hi everyone,
    I am building a simple program for turning on and off a single Bit.  The task is to turn ON the Bit for a period length T1, and OFF the Bit for a period length T2. T1 is normally different from T2, and can be controlled  by users. 
    Since T1 and T2 can be variable, they sometimes can be very long.
    If I use a Wait function inside a While loop, it needs long delay to be able to Stop the Main program.
    The same situation happens when I use Timed loop.
    Can anyone suggest me how to do this task?
    Thanks a lot. 
    Message Edited by tatuan on 04-12-2010 12:56 AM

    Here's another possibility using OpenG Wait ms:
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • How to stop an infinite Stream?

    I have a Stream instace which produces values using an infinite Supplier (it supplies values taken from an electronic sensor -- so unless the battery is low, the sensor will provide "for ever").
    The stream is processed by a Collector using Stream.collect() (e. g. imagine that the values from the sensor should be averaged; in fact what it does is a bit more compliacted maths).
    The problem is that the collector does not produce a result but hangs up, as the supplier does never stop providing more sensor values.
    So what I need is a limitation rule that stops the stream. While there is a Stream.limit(long) method, it actually does not solve my problem as in my case it is not practical to stop after a particular count, while I actually want to stop streaming when the sensor value exceeds a particular limit etc. (hence, voids an arbitrary rule).
    To sum up, what I need is Stream.limit(Predicate), i. e. the stream will stopped once the predicate becomes true.
    Unfortunately I did not find anything like that in JRE 8. :-(
    Is that planned for JRE 8.1 or JRE 9.0? Or is there a known (and sophisticated) workaround?
    Thanks!
    -Markus

    Would something like this do the trick?
    Stream.anyMatch((v) => {v > 1000})

  • Stopping a infinite loop

    I'm trying to write to a file by using a while loop. I read from the keyboard and then enter the while loop. I print to the file and then I read from the keyboard again. My problem is when I want to exit the loop by entering nothing I can't. The loop becomes infinite. Please help!!! Here is my code!!
    inputline = keyboard.readLine();//read the keyboard
    while ( inputline != null ){
    DiskOut.println( inputline );
    DiskOut.flush();
    inputline = keyboard.readLine();//read the keyboard again
    }//end while

    They're right...look at the following
    public static void doIt5() throws IOException
       BufferedReader stdIn = new BufferedReader(
          new InputStreamReader(System.in) );
       System.out.println( "type stuff...Press only ENTER to quit" );
       String input;
       //                1                    2           3
       while ( (input = stdIn.readLine()).equals("") == false )
          // do your thing...
          System.out.println( "echo: " + input );
          1 ---> assigning input from command line
          2 ---> comparing it to an empty string (if you just press ENTER, it
                 will be empty)
          3 ---> however, if something was typed, "input" would be non-empty
       // Same thing with a for loop...
       //              1                       2 & 3                1
       for ( input = stdIn.readLine(); !input.equals(""); input = stdIn.readLine() )
          // do your thing...
          System.out.println( "echo: " + input );

  • How to stop swf from looping?

    I'm trying to construct an animated slide where five text
    captions appear in sequence, and I want to use an arrow animation
    between each one, so that Caption 1 appears, then an animated
    arrow, then Caption 2, and so on. However, I can't get the arrow
    animations to play just once - they keep looping, which makes the
    finished diagram look ridiculous. What am I missing?

    Hi Julie:
    Thanks for the "thanks". To put names on all of the Captivate
    "AdobeCommunityExperts", they are ... in no real order:
    Paul DewHurst > The bloke from Liverpool, England >
    think chimney sweeps and "chim chim cheri"
    . . . Paul is the most creative of us in my opinion. He
    speaks softly and seldom, so listen when he does. I'm proud to say
    that Paul and I are mates. We've never met but I doubt most of you
    have a friend as true.
    Steve Shipe > Reston, VA, USA > think politicians,
    payoffs, and pork-barrels
    . . . Steve is none of the above. He's a great guy, but he
    does happen to live in the shadow of the U.S. Capitol. Steve is the
    "peacemaker" of the bunch, and can often be found keeping me out of
    digital jail.
    Rick Stone > Kansas City, Mo., USA > think lonely and
    verbose
    . . .Ever been to the Midwest? Nobody lives there, so Rick
    is lonely and uses the forums to talk - all the time. Constantly.
    He won't shut up! He also won't quit until he finds the solution to
    your problem. You want Rick on your team - or at least I do! Rick
    is actually a RoboHelp expert, but he switched allegiances to
    Captivate when it appeared RoboHelp was heading to extinction.
    Captivate users - rejoice ... he's that good!
    Larry Walther > DeWitt, IA, USA > think old, ornery,
    and impatient with pretenders (who make me look highly intelligent
    by their ignorance).
    . . . I am easily swayed to the side of
    1) those who really do know, and share it instead of
    bragging about it, and
    2) those who don't know ... admit they don't know - and
    appreciate help when they get it.
    Note that these are just the names of those who hold an
    "official" designation from Adobe . . . there are others who know
    who they are. I won't name names because I'd miss someone, but I
    can tell you that Australia, Great Britain, and New Zealand hold a
    special place in my list of very helpful blokes, as well.

Maybe you are looking for

  • Report Not showing result

    Hi! I am unable to get the result for my one of the item as checkbox. Other two are working properly .Please check and let me know wheres the problem please. ***INCLUDE ZSD_CONTRACT_LIST_T01_RENTAL1 . TABLES: vbak, vbap, wbrk, zsdsched,vbkd, fplt, fp

  • Two BenQ external displays not working with new 27" iMac

    I have a 27" iMac (newest model) and have been using it with a BenQ BL2710 monitor.  It's connected with a mini display port to display port cable.  It's been working great; I found that I had to uncheck the 'Displays have separate spaces' box in Mis

  • Opening a file opens welcome screen

    This sounds silly and is not stopping me from working but is starting to get annoying. When i right click or click to open a file in Dreamweaver, Dreamweaver opens and shows the welcome screen. The file is not loaded so i have to go back and click ag

  • I just set up my IPad Air and I can't find the free Apps, like Numbers?

    When I was trying to set it up, a box kept popping up asking me to download, but I couldn't get my ID/Password straightened out, Now that it's all ready, I can't find those apps that were included with my purchase of the IPad Air. How do I find those

  • How can I specify relative SubVI file path in VIs?

    I use LabVIEW 2009 Service Pack 1. SubVIs are referenced by absolute paths, so when I move them to a new folder I may need to set their paths again. How can I make a SubVI reference a relative path so that I don't have to set its path after moving VI