Do while loop doesn't end

my do while loop does not exits can help?
do{
               a++;
               System.out.print("Enter account number "+a+" (Press ENTER to exit) : ");
               account=CspInput.readString();
               item[a-1] = account;
               System.out.print("Enter credit card expenses for "+account+" : $");
               price=CspInput.readDouble();
               amount[a-1]= price;
               System.out.println("");
               if((a-1)==0)
                    summaryByMonth[i-1]=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
               else
                    summaryByMonth[i-1]+=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
               totalAmount[i-1]+=amount[a-1];
          }while(account != null && account != " ");

si0ngch33 wrote:
my do while loop does not exits can help?
do{
               a++;
               System.out.print("Enter account number "+a+" (Press ENTER to exit) : ");
               account=CspInput.readString();
               item[a-1] = account;
               System.out.print("Enter credit card expenses for "+account+" : $");
               price=CspInput.readDouble();
               amount[a-1]= price;
               System.out.println("");
               if((a-1)==0)
                    summaryByMonth[i-1]=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
               else
                    summaryByMonth[i-1]+=item[a-1]+"\t\t"+fmt.format(amount[a-1])+"\n";
               totalAmount[i-1]+=amount[a-1];
          }while(account != null && account != " ");Either use a debugger or put some print statements in the loop to see what the actual value of account is:
Example:
do{
    //... bunch of code
    System.out.println("DEBUGGING - account is '"+account+"'");
}while(account != null && !account.equals(" "));

Similar Messages

  • While loop doesn't stop until 2 more clicks

    I have to say I am really not familiar with LV at all, but Im learning.
    So, why is that after I clicked stop bottom, I had to click my OK button twice, then my program stopped. Why it can't stop immediately?
    Besides, if I want to some the dice result by array, which wire am I missing?
    Thank you!
    Solved!
    Go to Solution.
    Attachments:
    dice.vi ‏15 KB

    Hi RawtoLV,
    You have a while loop within a while loop. When you run the other while loop stops when you pressed the stop button, the inner while loop still runs. Since your OK button is using Latch when released, what i noticed is that when you pressed that OK button, it quickly switched to from true to false which didn't stop that while loop operation (could be due to the wait). May I ask what are you actually doing with the sequence structure?
    I would suggest using event structure instead (http://zone.ni.com/reference/en-XX/help/371361K-01/glang/event_structure/):
    here some more info on event structure:
    http://www.ni.com/white-paper/3331/en/
    http://www.youtube.com/watch?v=8eO64fo3Pho
    Warmest regards,
    Lennard.C
    Learning new things everyday...

  • Yes/No - Do/While loop at the end of the script

    Hello !
    I am kinda confused of the responses of my script.
    echo "Number comparison"
    do
    $x = Read-Host "Please enter your first number you want to compare with"
    $y = Read-Host "Please enter your second number you want to compare with"
    if($x -gt $y)
    echo "$x is greater than $y."
    elseif($x -lt $y)
    Write-Host "$x is lower than $y."
    else
    echo "$x is equals $y."
    while (($again = Read-Host "Do you want to do it again?") -eq "No","n","N")
    I have an assumption what might be the error, but I'm not really sure if it's possible to save the input of $again either in the brackets or to add {} below while. I tried but nothing was successful.
    My objective is to repeat the program when it's finished, to give me/user the possibility to start it again if I type in "Y,y or yes" and stop it when I type "N,n or no". Nothing should happen if there's any other character written except
    the defined ones.
    greetings!

    Do While example:
    Write-Output 'Number comparison'
    Do {
    $x = Read-Host 'Please enter your first number you want to compare with'
    $y = Read-Host 'Please enter your second number you want to compare with'
    If($x -gt $y) {
    Write-Output "$x is greater than $y."
    } ElseIf($x -lt $y) {
    Write-Output "$x is lower than $y."
    } Else {
    Write-Output "$x is equals $y."
    $again = Read-Host 'Do you want to do it again?'
    } While ($again -eq 'Yes' -or $again -eq 'y')
    Do Until example:
    Write-Output 'Number comparison'
    Do {
    $x = Read-Host 'Please enter your first number you want to compare with'
    $y = Read-Host 'Please enter your second number you want to compare with'
    If($x -gt $y) {
    Write-Output "$x is greater than $y."
    } ElseIf($x -lt $y) {
    Write-Output "$x is lower than $y."
    } Else {
    Write-Output "$x is equals $y."
    $again = Read-Host 'Do you want to do it again?'
    } Until ($again -eq 'No' -or $again -eq 'n')
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • ReadUTF() and exiting a server while loop

    What I want to do is simple.. I want to be able to type "exit" into a client and send that message to the server... And exit the server while loop as a result.. Here is what I tried.
    //server code
    while(true)
    //bla bla bla
    //bla bla bla
    String message = socket.readUTF();
    if( message == "exit" )
    break;
    // bla bla bla
    however, when I type exit and send the message, this while loop doesn't break.. I'm new to java so I'm wondering if I'm messing up syntax somewhere.. It seems like it should work fine, whats going on?

    if(message.equals("exit"))

  • Stop While loop

    Hi
    I have a while loop with a cycle time of 100 sec, when I stop it I have to wait 100 sec untill the while loop stops.
    There is any manner to stop it immediatly?
    Thanks

    Why are you using a property node for a control that is not accessed within the loop?  And the conditional terminal is set to run if True. 
    Your while loop doesn't make sense.. Can you post the entire code (attach your vi) and explain what you are trying to do?
    R

  • While loop in query is going under infinite loop

    Declare
    @StartDate_in date,
    @EndDate date
    Set @StartDate_in = cast('2000-01-01' as date)
    Set @EndDate = cast('2010-12-31' as date)
    declare @month int
    declare @year int
    declare @endyear int
    declare @startdate date
    set @startdate= @startdate_in
    set @month = month(@StartDate_in)
    set @year= year(@StartDate_in)
    set @endyear= year(@EndDate)
    while @year<=@endyear
    Begin
    while month(@startdate)<=12 and @year<=@endyear
    begin
    print (@year);
    print (month(@startdate));
    INSERT Into target
    ( YEAR,
    MONTH,
    MONTH_VAL,
    L_DT,
    U_DT,
    S_DT,
    E_DT
    Values
    ( datepart(yyyy,@StartDate) ,
    datepart(month,@StartDate) ,
    substring(datename(month,@StartDate),1,3),
    GETDATE(),
    GETDATE(),
    (GETDATE()-1),
    null
    set @StartDate = dateadd(month,1,@StartDate);
    set @month=1;
    end
    set @year=@year+1;
    print (@year);
    print (@month);
    end
    The query although with exit condtion given in the while loop is not ending and executing infinetly
    ddl of target
    CREATE TABLE target(
    [TIME_ID] [int] IDENTITY(1,1) NOT NULL,
    [START_DT] [date] NULL,
    [E_DT] [date] NULL,
    [L_DT] [datetime] NULL,
    [U_DT] [datetime] NULL,
    [YEAR] varchar (5) NULL,
    [MONTH] varchar(5) NULL,
    [MONTH_VAL] [varchar](5) NULL
    ) ON [PRIMARY]
    GO
    Mudassar

    Try followings:Declare
    @StartDate_in date,
    @EndDate date
    Set @StartDate_in = cast('2000-01-01' as date)
    Set @EndDate = cast('2010-12-31' as date)
    declare @month int
    declare @year int
    declare @endyear int
    declare @startdate date
    declare @innerloopyear int
    set @startdate= @startdate_in
    set @month = month(@StartDate_in)
    set @year= year(@StartDate_in)
    set @endyear= year(@EndDate)
    set @innerloopyear = @year
    while @year<=@endyear
    Begin
    while month(@startdate)<=12 and @year>=@innerloopyear
    begin
    print (@year);
    print (month(@startdate));
    INSERT Into target
    ( YEAR,
    MONTH,
    MONTH_VAL,
    L_DT,
    U_DT,
    S_DT,
    E_DT
    Values
    ( datepart(yyyy,@StartDate) ,
    datepart(month,@StartDate) ,
    substring(datename(month,@StartDate),1,3),
    GETDATE(),
    GETDATE(),
    (GETDATE()-1),
    null
    set @StartDate = dateadd(month,1,@StartDate);
    set @innerloopyear = YEAR(@startdate)
    set @month=1;
    end
    print 'hello'
    set @year=@year+1;
    --set @StartDate = DATEADD(year,1,@StartDate)set @innerloopyear = @year
    print (@year);
    print (@month);
    end
    I have formatted change in "Bold".

  • Triggered finite acquisition in a while loop - speed limit ? (newbi)

    Hello,
    I suppose the question already asked and answered but I didn't find exactly what I was looking for, so I'm sorry if it exists somewhere here.
    Usil LV7 with NI 4474 (PCI) acquisition board, PCI-6601 as external trigger, I would like to perform a repeted finite acquisition, starting on external trigger.
    Trigger is working fine (I need up to 20 impulses /s), but the finite acquisition in a while loop doesn't seem to follow the speed. I was thinking it was a CPU proble m and I removed everything which was not absolutely useful.
    So I have a VI with
    1) External trigger output. (express)
    2) While loop with DAQmx Read Analogic Waveform 1 channel N sample, with a DAQmx task as an i
    nput (specifying 50000Hz sample rate, 1000 samples, external trigger start)
    I was able to climb up to 10 cycles/s but above, some ext. triggers are missed.
    Question : where is the problem ? On continuous acquisiton, I can acquire up to 100.000 samples/s but on finite acquisition, I cannot perform 20x1000 samples/s ? What actually specifies the while loop itteration speed ?
    Thank you for your ideas, I'm joining VI capture...
    Attachments:
    vi_ai_external_triggered.JPG ‏31 KB

    I did not the test, but first of all, I think it is not the good way to call your task at each iteration. It is better to configure all elements concerning your aquisition outside the while loop. (external trigger, sampling rate, number of samples.... After you start the DAQmx read (only) in the while loop.
    I think you'd better start from an example from the labview library (attached file)
    Hope it will help you
    Regards
    Attachments:
    Acq&Graph_Voltage-Int_Clk-Dig_Start.vi ‏71 KB

  • Can't write to instrument in while loop.

    in  my case, I use 2 while loop for the progarm. one is to write the data to the instrument, another one is use local variable to change the data depend on time. the problem is the data which need write to the instrument does change. but another while loop doesn't write it to the instrument unless I push highlight excution in the diagram or choose save as in the file. could anybody help me to find the problem?

    Hi Akuma,
    the fact that it works when you highlight execution implies (perhaps) a race condition. The lightbulb serializes the execution of your VI, so that functions execute in succession although they don't depend on each other. When you then run the VI in realtime, some functions are executed at the same time, e.g. "VISA flush buffer" and "VISA write". It is important to define the order the VIs execute on your VISA interface for instance by wiring the error-cluster.
    If this doesn't help, then post your VI (or a simplified version) or a screenshot of the diagram.
    Greets, Dave
    Greets, Dave

  • Why doesn't my while loop end?

    * Main method
    public static void main(String args[])
    Scanner sc = new Scanner(System.in);
    //get input
    String hexa = "nothing";
    while (hexa != "q")
    System.out.println("");
    System.out.println("Please enter a hexadecimal to convert to binary, enter q to quit");
    hexa = sc.next();
    int hexlength = hexa.length();
    for (int i = 0; i < hexlength; i ++)
    char hexadec = hexa.charAt(i);
    //send to subprogram
    findBinary(hexadec, hexlength);
    why doesn't my while loop end when i enter q?

    The equals method returns a boolean (true/false). So you simply negate the returned value.
    if( ! methodCall()) {
    }

  • 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
    }

  • Allow state machine while loop to end only in 1 of the states?

    What is the best way to ensure that the while loop that surronds state machine case structure only ends in a certain one of the states?

    I have solved the problem of having the VI not stopping (apparently it was due to an event structure). However, now I have another slight problem. I need the state machine to terminate on either of two conditions:
    1) If a stop button is pressed
    OR
    2) if the end of the sequence is reached.
    As I have implemented it so far the VI terminates because of the second condition and does not allow me to terminate it by pressing a 'Stop' boolean button. I know that this might be a bit fundamental and simple but I'm new with state machines on labview.
    Thanks.
    Attachments:
    State machine.vi ‏21 KB

  • End a while loop

    For this example:
    int x = 1, y = 2;
    while (x == 1)
    if (y = 2)
    y -= 1;
    if (y = 1)
    y -= 1;
    }Is there a line I can put in the first if statement block to make the loop and and repeat? I'm having a problem with if statements that after one is true, it makes one following it also true. I only want one to be executed, so if I could make the while loop repeat after an if statement is true, I could fix that problem

    I'm having a problem with if statements that after one is true, it makes one following it also true. I only want one to be executedOr perhaps "else if"
    while(foo) {
      if(cond1) {
        cond2 = true;
      } else if(cond2) {
        cond1 = true;
    }

  • Ending a while loop inside a while loop

    How do I make a while loop run as long as the while loop that contains it is running? I tried wiring both conditional terminals to a stop button in the outer loop, but that doesnt seem to work? Is there another way?
    Thanks.

    Hi Jasonalan,
    I am not sure what you are trying to implement, but it is true that the loops are not terminating because of data dependency. The stop button in the outer loop will not be read until the inner loop terminates.
    If you wish to terminate the two nested loops using a single stop button, you should read the stop button inside the inner loop and wire it to the conditional terminals in both the inner and outer loop. Again, there is no point in doing this unless you have some other logic along with the stop button to stop the loops. If only the stop button is being used to stop both the inner and outer loops, the outer loop will only execute once. In that case, you can just use a sequence structure followed by a single while loop.

  • How to stop while loop

    I can't figure out how to stop a while loop in my labview program. 
    When the user presses the Run arrow in the toolbar I want my program to begin reading the serial port for GPS messages.  These messages should be displayed on the front panel.  Currently I have this read/display in a while loop.  The program is also waiting for an extrenal trigger.  When that trigger arrives, I want to grab the current string from the serial port and save it and continue reading and displaying the serial/gps string.  This trigger starts the other parts of the program- signal generation, recording, and saving data which need to run concurrently with the serial/gps reading/displaying.  Once the AO and AI have finished and the data have been written to disk, I want the program to stop.  The serial/gps messages should be updating this whole time.  Only when the data are written to disk should the whole program end.  This whole sequence of events should only be done once when the user preses the Run arrow. 
    So far I'm unable to pluck the serial string when the trigger comes in if I'm watching the serial port all the time.  The program also doesn't stop when it finishes writing to disk because the read serial while loop is still running.  I don't want to use a front panel stop button.  The program should stop itself when the data havebeen written. 
    I'm really stumped on this one but I'm new to LabVIEW so I'm sure there's an easy solution to this. 
    Thanks for any and all help. 
    Attachments:
    SPoleLakeChirp.vi ‏199 KB

    Dennis and altenbach-  Thank you both for your patience. 
    I was trying to do just what Dennis suggested-"As I said, setting a local variable is one way." even before posting to this forum, but I couldn't get my local variables to reflect changes made elsewhere in the program and I wasn't able to wire from them because they were writes.  The critical part I was missing was how to change a local variable from a write to a read.  It was staring me in the face the whole time- just right click.  When I finally found it, my problems were solved. 
    altenbach- thank's for putting the figures together.  I do understand the logic and wiring there, but I was really trying to avoid stop buttons.  The program should be smart enough to figure out when to stop.  And using local variables turns out to be one way of solving this.  I still have some clean up to do, but I've included my current working version just so you can see how I implimented your suggestions.  There's still a lot of clean up to be done, but I'm delighted to be able to watch the serial/gps messages until I'm done reading in data.  At first I had this stop variable set in the final sequence frame.  That didn't work because I wasn't getting to the final frame because the loop wasn't finishing.  Once I placed the stop variable in the same frame as the while loop it began stopping when it should. 
    If you have other comments/critiques about the wiring diagram I'm earger to hear them.  I'm considering the structure finished, however.  It still needs cleaning up and commenting, but I'm satisfied with the functionality. 
    Thanks,
    Peter
    Attachments:
    SPoleLakeChirp.vi ‏210 KB

  • Problem with while loop in thread: starting an audiostream

    Hello guys,
    I'm doing this project for school and I'm trying to make a simple app that plays a number of samples and forms a beat, baed on which buttons on the screen are pressed, think like fruity loops. But perhaps a screenshot of my unfnished GUI makes things a bit more clear:
    [http://www.speedyshare.com/794260193.html]
    Anyway, on pressing the play button, I start building an arraylist with all the selected samples and start playing them. Once the end of the "screen" is reached it should start playing again, this is the while loop:
    public void run(){
            //System.out.println("Wavfiles.size =" + getWavfiles().size());
            System.out.println(repeatperiod);
            if (getWavfiles() == null) {
                System.out.println("Error: list of Wavfiles is empty, cannot start playing.");
            else{
                if(!active) return;
                while(active){
                    System.out.println("Wavfiles.size =" + getWavfiles().size());
                    for (int i=0; i<getWavfiles().size(); i++){
                        Wavplayer filePlayer = new Wavplayer(getWavfiles().get(i).getStream());
                        Timer timer = new Timer();
                        //timer.scheduleAtFixedRate(filePlayer, getWavfiles().get(i).getStartTime(),repeatperiod);
                        timer.schedule(filePlayer, getWavfiles().get(i).getStartTime());
                    try {
                        Thread.sleep(repeatperiod);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(LineBuilder.class.getName()).log(Level.SEVERE, null, ex);
        }But once the second iteration should begin, I'm getting nullpointerexceptions. These nullpointerexceptions come exactly when the second period starts so I suppose the sleep works :-) The nullpointerexception comes from the wavfile I try to play. Wavfile class:
    package BeatMixer.audio;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.util.TimerTask;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.UnsupportedAudioFileException;
    public class Wavplayer extends TimerTask {
            private SourceDataLine auline;
            private AudioInputStream audioInputStream;
         private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
         public Wavplayer(ByteArrayInputStream wavstream) {
              try {
                   audioInputStream = AudioSystem.getAudioInputStream(wavstream);
              } catch (UnsupportedAudioFileException e1) {
                   e1.printStackTrace();
                   return;
              } catch (IOException e1) {
                   e1.printStackTrace();
                   return;
                    AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
                    try {
                   auline = (SourceDataLine) AudioSystem.getLine(info);
                   auline.open(format);
              } catch (LineUnavailableException e) {
                   e.printStackTrace();
                   return;
              } catch (Exception e) {
                   e.printStackTrace();
                   return;
        @Override
         public void run() {
                    System.out.println(auline);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
              try {
                   while (nBytesRead != -1) {
                        nBytesRead = audioInputStream.read(abData, 0, abData.length);
                        if (nBytesRead >= 0)
                             auline.write(abData, 0, nBytesRead);
              } catch (IOException e) {
                   e.printStackTrace();
                   return;
              } finally {
                   auline.drain();
                   auline.close();
    }auline is null on second iteration, in fact, getAudioInputStream doesn't really work anymore, and I don't know why because I don't change anything about my list of wavfiles as far as I know... Any thoughts or extra info needed?
    Edited by: Lorre on May 26, 2008 12:22 PM

    Is my question not clear enough? Do you need more info? Or is nobody here familiar with javax.sound.sampled?
    Edited by: Lorre on May 26, 2008 2:07 PM

Maybe you are looking for

  • Mouse over dock icon no longer indicates "application not responding"

    A very convenient feature seems to be missing from Snow Leopard. In prior versions, if an application was not responding, holding the cursor over its dock icon would display "[Application] Not Responding" and also an option to Force Quit. This status

  • How to display three separate input numbers as one formula display

      I need to create a front panel with three numerical inputs, these inputs are part of a formula equation. Also in the the same front panel should show the entire equation with the numerical inputs.

  • Ugh: "iTunes could not connect to the iTunes Music Store"

    G5, OSX 10.4.10, iPod 5G 1.2.1, iTunes 7.3.1. Actually I have not been able to access the music store for over a year. It stopped working after an iTunes upgrade I do not recall. 2G finally died and I just bought a new 5G. I can enter the music store

  • Business Roles - Risk analysis

    Hi All, We are on GRC SP13. We are using business roles for provisioning to end users. When role owner is performing risk analysis for business roles, results are proper according to defined ruleset only if "SYSTEM" field is empty. If system is selec

  • Critical error found while installing Dreamweaver CS4

    Hi guys! Please help me. I can't install my dreamweaver CS4 and I got this error message "Critical errors were found in setup for Adobe Dreamweaver CS4 Session has dependencies than cannot be satisfied. The installer database is invalid: please re-in