While loop not performing correctly

When I enter ANY number, the second while loop in the code below executes. It should not execute when 117, 239, 298, 326, or 445 is entered. I can't seem to figure out why this does not work, and I do not know what else to try.
Hope someone can just give some assistance. Thank you!
If I need to supply the entire program, just let me know.
while(! done)
               try
                    System.out.println("Enter the flight number");
                    entry = keyboard.nextInt();
                    while((entry != 117) || (entry != 239) || (entry != 298) || (entry != 326) || (entry!= 445))
                         System.out.println("Flight number must be 117, 239, 298, 326, 445");
                         System.out.println("Please try again");
                         entry = keyboard.nextInt( );
                         done = true;
               catch(InputMismatchException e)
                    keyboard.nextLine();
                    System.out.println("Not the correct entry");
                    System.out.println("Please try again");
          }

JosAH wrote:
paulcw wrote:
The outer loop loops on "not done", but in the body of that loop, done is unconditionally set to true. So the outer loop will only run once. Therefore it's pointless. I'm guessing that you meant to only set done to true if the user inputs "quit" or something.The 'not done' loop will iterate again if the user supplied incorrect input (not an int).Man that's a confusing flow of control. So if the user types in anything other than a number, it's causes a parse error (basically) and the exception causes it to skip the command to stop, and that makes it loop again.
So apparently 3/4 of the people looking at that code didn't get it at first.
It reminds me of the veda about Mel.
Come up with something clearer.

Similar Messages

  • Parallel while loops not running in parallel

    I am collecting data from a PCI 4351 board and a 6070E board. These are connected to a TC 2190 and a BNC 2090. I do not need exact sychronization, however I do need them to collect data at different rates. Currently I am using two while loops to perform this, but they run sequentially in stead of simultaneously, that is, the second while loop waits for the first one to finish before running. Is there any way I can get these to run both at the same time instead of one after the other?
    Attachments:
    Parallel Whiles.vi ‏89 KB

    Any way you do it, you're going to have to sequentially read from the data buffer, and the implementation you have now may be the fastest, if not the most accurate.  I would recommend that you either put a wait statement in each loop if the two data reads need different timing, or just wire the error cluster from one's output to the other's input and have them both in the same loop.  At least that way you are always certain which is executing before the other.  Also, in the dataflow (wired together) example, I would still recommend a wait statement, just to be on the safe side.  Even if you have a wait of 10 ms it may save you from spinning your loop pointlessly.
    =============
    XP SP2, LV 8.2
    CLAD

  • For Loop not acting correctly...

    Hi everyone,
    I have this For Loop in JavaScript which is not working correctly and I really have no idea why it is acting like so... I don't if anyone has already encountered this issue and I'd like to know if there's a fix for this or what am I doing wrong...
    I have a normal for until the count is done like this -> for (var c = 0; c < frmResourceReq.instanceManager.count; c++){}
    If I put this loop with only a messageBox it will do it right, so if the count is 1, it will do it once, if the count is 2 it will do it twice...
    The loop with the actual code is not acting like so.. if the count is 1, it will do it once, but if the count is 2 it will do it once also...
    At 1 point it was acting weird so I decided to make the condition with  'c <= frmResourceReq.instanceManager.count'
    Now if the count is 1, it is not working because it crashes once it execute it the second time, but if I have a count of 2 or 3 it will execute the right number of times...
    Does anyone have any idea what is creating this issue, seems like I really can't figure it out.
    Thanks for your time.

    Hi,
    to avoid that the loops condition is unnecessarily calculated again for every iteration it's recommended to save the condition in a variable first.
    for (var c = 0, n = _frmResourceReq.count; c < n; c += 1) {
        //code to execute
    As the instance count of iteration frmResourceReq may change already while the loop runs it can end with unexpected results.

  • Trouble with while loop, not sure what to put in it in my project

    I'm making a class to a simple command line craps game. I must use a while loop to implement craps rules. The rules that i was given are:
    if your first roll is a 4, 5, 6, 8, 9, or 10, you roll again until either you get a 7 (you lose) or you get the number from your first roll. (i thought 7 or 11 wins, like in the next example)
    yeah, thats right, not very good directions. The first directions i had for a different way of doing it using if and else statements were:
    The player rolls the two dice.
    If the sum of the resulting die values is 7 or 11, the player wins.
    If the sum is 2, 3, or 12, the player loses.
    If something else is rolled, the player has to roll again to determine the outcome.
    If the sum of the second roll is the same as what the player rolled the first time, the player wins. Otherwise the player loses.
    (You might get a pair of dice and play a few rounds to try it.)
    here's my code that i have so far for my craps class, in the middle section, i have previous code that i used for if else statements, that is what im trying to replace: package games;public class Craps {
    private Dice dice1;
    private Dice dice2;
    private int gamesPlayed;
    private int gamesWon;
    private boolean lastGameWon;
    private boolean gameOver;
    private int firstRoll;
    private int secondRoll;
    public Craps() {
    dice1 = new Dice(6);
    dice2 = new Dice(6);
    gamesPlayed = 0;
    gamesWon = 0;
    lastGameWon = false;
    firstRoll = 1;
    secondRoll = 2;
         //returns firstroll
    public int getFirstRoll(){
    return firstRoll;
         //returns secondroll
    public int getSecondRoll(){
    return secondRoll;
    public int getGamesPlayed(){
    return gamesPlayed;
    public int getGamesWon(){
    return gamesWon;
    public boolean lastGameWon(){
    return lastGameWon;
         public int nextSum()
         dice1.roll();
         dice2.roll();
         return dice1.getSideUp() + dice2.getSideUp();
    public void play()
              firstRoll = nextSum();
    if (firstRoll == 7 || firstRoll == 11)
              gameOver = true;
              gamesWon++;
              if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
              gameOver = true;
                   else{
                   gameOver = false;
              while (gameOver == false)
              secondRoll++;
    public String toString()
    return "games - " + gamesPlayed + ", won - " + gamesWon + ", last game won - " + lastGameWon + " First Roll - " + firstRoll +
    ", Second Roll - " + secondRoll;
    i'm really confused on how to get the while loop will keep starting the game over if it is false, am i using the right approach? Also i have to use a while loop, its for a school project.
    thanks.

    The code you asked for could be:
    package games;
    public class Craps {
        private Dice dice1;
        private Dice dice2;
        private int gamesPlayed;
        private int gamesWon;
        private boolean lastGameWon;
        private boolean gameOver;
        private int firstRoll;
        private int secondRoll;
        public Craps()
            dice1 = new Dice(6);
            dice2 = new Dice(6);
            gamesPlayed = 0;
            gamesWon = 0;
            lastGameWon = false;
            firstRoll = 1;
            secondRoll = 2;
         //returns firstroll
        public int getFirstRoll(){
            return firstRoll;
         //returns secondroll
        public int getSecondRoll(){
            return secondRoll;
        public int getGamesPlayed(){
            return gamesPlayed;
        public int getGamesWon(){
            return gamesWon;
        public boolean lastGameWon(){
            return lastGameWon;
        public int nextSum()
            dice1.roll();
            dice2.roll();
            return dice1.getSideUp() + dice2.getSideUp();
        public void play() {
            gamesPlayed++;
            firstRoll = nextSum();
            if (firstRoll == 7 || firstRoll == 11)
                gamesWon++;
                lastGameWon = true;
            else if (firstRoll == 2 || firstRoll == 3 || firstRoll == 12)
                lastGameWon = false;
            else
               secondRoll = nextSum();
               if (firstRoll == secondRoll)
                  gamesWon++;
                  lastGameWon = true;
               else
                  lastGameWon = false;
        public String toString()
            return "games - " + gamesPlayed + ", won - " + gamesWon + ", last game won - " + lastGameWon + " First Roll - " + firstRoll +
                    ", Second Roll - " + secondRoll;
    }I'm not sure of craps rules, the code above makes a first roll and if game isn't won or lose at once (7 and 11 wins, 2,3 or 12 lose) a second roll is done. If the second roll is equals to the first made then the game is won else the game is lose. Is it right?

  • While loop not breaking?

    I'm writing a parser for some text files.
    My setup looks like so:
    public void parseFile(String fileNameIn) throws IOException{
            BufferedReader br = new BufferedReader(
                    new FileReader(fileNameIn));
            String line = null;
            line = br.readLine();
            while(line != null){
                //do a bunch of stuff
                line = br.readLine();
    }I hit a line that == null when I am parsing and for some reason it is not breaking out of the while loop? I have no idea why.

    Sch104 wrote:
    I hit a line that == null when I am parsingNo, you don't. That condition causes control to exit from the loop when it reaches the end of the file. A line of text can't be null. Perhaps it might contain zero characters, or only white space, but that doesn't make it null. If you want to break out of the loop when you reach an empty line, you'll have to write a test for an empty line.
    (Don't worry about what ibanezplayer85 said. Your code is perfectly good for processing a text file, it's equivalent to what he/she posted. I think your version is easier to understand, but you will very frequently encounter his/her version in code so it doesn't hurt to understand it, though.)

  • Clip looping not working correctly unless I edit clip in Waveform editor (CS6)

    I record a short clip
    I use the, razor, slip or time selection to trim the clip to the exact length I want it to be.
    I rt-click the clip and enable looping
    I go to the right edge of the clip and stretch the clip to make it loop one or more times.
    Problem, the clip loops but not at the begin and end point I expected based on #2 above.
    I eventually went into the wave form editor and just deleted the dead air at the beginning of the clip (but not at the end) and now the looping feature works as expected.
    Am I missing something?  Is this the correct behavior?  Do I have to edit a clip in waveform editor to make it loop correctly?
    Thanks, I'm new to AA and just getting started with CS6 version.

    bmfm_ wrote:
    I have quite a lot XDCAM EX 50i clips which are all in one sequence that is used as source.
    Now fortunately one can choose to either have a sequence as source edited in nested or as individual tracks. Very nice!
    Very bad is that 3 point editing only works when "nested" is activated. Again, very bad!
    Hi bmfm,
    I think I know what's going on. The behavior you describe happens when you try to edit back into your original sequence. Can try making a new sequence to cut your selects into? See the page in help for details: http://helpx.adobe.com/premiere-pro/using/edit-sequences-loaded-source-monitor.html
    Thanks,
    Kevin

  • Looping Not Working Correctly In CS4

    In Encore CS4 I have a DVD with the first menu that is set to loop forever.  After I burn the DVD, the menu loops twice then stops.  I tried again to set the loop number to 1024.  The results were the same, the menu looping twice and stopping. 
    I've tried in four different DVD players.  In addittion, in preview mode the menu seems to loop correctly.
    Does anyone have any ideas or suggestions?

    Thank you.
    The T-Y's are as good as it gets.
    Burn speed can cause playability issues, and I normally step down to about 1/2 of the max. As no set-top player is certified to play any burned DVD, I want to eliminate as many potential problems, as I can.
    Now, I do not recall hearing of any Looping Bug in CS4, but also do not have CS4. Maybe others have experience with this issue.
    Sorry that I do not know even where to look next.
    Good luck,
    Hunt

  • Why does my While loop not work?

    I was using the SetInterval timer but this kept causing problems getting the timing right,
    So I thought - get the loop to work infiitely...
    var cond=0;
    while (cond !=1){
    $("#DivStage1").fadeIn(1000);
    $("#DivStage1").delay(6500).fadeOut(500); //8000
    $("#DivStage1_1").show("slide", {direction:'left'}, 1000);
    $("#DivStage1_1").delay(6500).hide("slide", {direction:'left'},500);
    $("#DivStage1_2").delay(1000).show("slide", {direction:'left'}, 1000);
    $("#DivStage1_2").delay(5500).hide("slide", {direction:'left'}, 1000);
    $("#DivStage2").delay(8000).fadeIn(1000);
    $("#DivStage2").delay(17000).fadeOut(500); //8000 to 16000
                            $("#DivStage2_1").delay(8000).show("slide", {direction:'left'}, 1000);
                             $("#DivStage2_1 h2 #1 style='color: #FFF;'").show();
                             $("#DivStage2_1").delay(16000).hide("slide", {direction:'left'},500);
    The page does not execute the loop.
    Thanks in advance for any feedback

    Create a function for the loop and call the function when the document is ready.
    Don't forget to include the jQuery library, jquery.js or similar.

  • Loops not playing correctly when added to project

    When I listen to loops in the library (specifically drums) they sound fine. I drag them over to my project and get a pop-up saying: "EXS24 instrument "2-Step Remix.exs" not found." The loop is added to my project, but now sounds odd and distorted. How can I fix this?

    Seems like you are having problems with accessing Logic's library content (if you have it all installed of course). That can be resolved by checking/repairing disk permissions.

  • Loop not working correctly in smartform

    Hi Experts,
    I have developed a smart form wherein,  the import params of form is a table (multiple records).The design of the form is, the first 10 lines is populated with a static text followed by the import table and follwed by a conclusion text. in simple words the design is, in the header a static text (hard coded text) will be populated in the main body an internal table will be populated and in the footer a static text (hard coded text) will be populated.Initially I have created three seperate windows for header, main body and footer, this was working fine for few records (import table) sometimes it happened the records were very huge and table entries over lapped the footer text. How to handle this kind issue? Can we increase the page size dynamically?? and also as per the user requirement the output of the form should have a provision to download the form on thier desktop in word format. Can some one help me in building this functionality.
    Thanks and Regards,
    Srini...

    Hello Mr. Srinivas,
    There is no provision to download the form in word format, but if you want to still download the form in real means open smartforms --> Utilities(M) --> download form.
    this will download the whole program wahtever you hvae chnge made in this. Make the back copy of form and after edition in form make down load again this form and than find out the differnce. May be this will be helpful. And also if yr loop is not working with smartform. Do write the similar code in yr driver program for the loop this will definetely helpful.
    Regards,
    Akg
    Edited by: akg.amit on Mar 25, 2011 10:08 AM

  • While loop not terminating

    hmm. very strange to me. i have a condition that if a person enters QUIT then the program should terminate but for some reason its not terminating.
    import java.util.*;
    class BicycleTest {
         public static void main(String[] args) {
              BNode start, tail, next;
              start = null;
              Scanner s = new Scanner(System.in);
              System.out.println("Enter name");
              String name = s.next();
              if(!name.equalsIgnoreCase("QUIT")) {
                   start = new BNode(new Bicycle(name), null);
                   tail = start;
                   while(true) {
                        name = s.next();
                        if(name.equalsIgnoreCase("QUIT")) break;
                        next = new BNode(new Bicycle(name), null);
                        tail.setNext(next);
                        tail = next;
    }

    jverd when you say an older version that means the
    java version or the compiler? No, an older version of your code. Like you changed it (to what you first posted) but forgot to save or recompile. Maybe before you had equals instead of equalsIgnoreCase, or something like that.

  • Firefox will not perform correctly when I open new Firefox windows

    The only Firefox windows that work correctly are the first window I open (which has tabs saved) and the window that opens when I go into tools> options> help, any other new Firefox window I open wont let me open a new tab or window from the page I am on (I can still open new tabs with the bookmarks or new tab button), I can't use the back page/forward page/refresh page/stop loading page buttons and the page I am on doesn't show in the address bar.

    go to Help Menu -> select "Restart with Add-ons Disabled"
    Firefox will close then it will open up with just basic Firefox. Now do this:
    -> Update Firefox to the latest version by going to Help Menu -> About Firefox -> click Check for Updates -> if an updated version is found then download the latest version and install it. After that follow these steps:
    -> Update ALL your Firefox Plug-ins https://www.mozilla.com/en-US/plugincheck/
    -> go to View Menu -> Zoom -> click "Reset"
    -> go to View Menu -> Page Style -> select "Basic Page Style"
    -> go to View Menu -> Toolbars -> select Menu Bar and Navigation ToolBar -> unselect all unwanted toolbars
    -> go Tools Menu -> Clear Recent History -> ''Time range to clear: '''select EVERYTHING''''' -> click Details (small arrow) button -> place Checkmarks on ALL Options -> click "Clear Now"
    -> go to Tools Menu -> Options -> General -> ''When Firefox starts : '''select "Show My Home Page"''''' -> Type the address of the website which you want to be your HomePage e.g. http:www.google.com -> place Checkmark on "Show the Downloads window when downloading a file" -> select Radio Button option2 "Always ask me where to save files"
    -> go to Tools Menu -> Options -> Content -> place Checkmarks on:
    1) Block Pop-up windows
    2) Load images automatically
    3) Enable JavaScript
    -> go to Tools Menu -> Options -> Privacy -> History section -> ''Firefox will: '''select "Use custom settings for history"''''' -> PLACE CHECKMARKS on:
    1) Remember my Browsing History
    2) Remember Download History
    3) Remember Search History
    4) Accept Cookies from sites -> select "Exceptions..." button -> Click "Remove All Sites" at the bottom of "Exception - Cookies" window
    4a) Accept Third-party Cookies -> under "Keep Until" select "They Expire"
    -> REMOVE CHECKMARK from CLEAR HISTORY WHEN FIREFOX CLOSES
    -> go to Tools Menu -> Options -> Security -> place Checkmarks on:
    1) Warn me when sites try to install add-ons
    2) Block reported attack sites
    3) Block reported web forgeries
    -> Click OK on Options window
    -> click the Favicon (small drop down menu icon) on Firefox SearchBar (its position is on the Right side of the Address Bar) -> click "Manage Search Engines" -> select all Unwanted Search Engines and click Remove -> click OK
    -> go to Tools Menu -> Add-ons -> Extensions section -> REMOVE All Unwanted/Suspicious Extensions (Add-ons) -> Restart Firefox
    You can enable your Known & Trustworthy Add-ons later. Check and tell if its working.

  • Button instance not performing correctly

    i have a button that when it is held down for over 2 seconds
    it will jump to a frame, and jump to a different frame if just
    pressed and not held down. I have the code working, I am trying to
    apply it to an instance of another button(named fwd1). If i drop
    the actionscript in the first frame of my actions layer it works,
    but not just for the frames where the button instance is defined as
    fwd1, but all frames of the button that aren't given an instance
    name. If I give the button an instance name other that fwd1
    somewhere on the timeline, then the button wont work on any frame
    past that point, even if i setup a keyframe and add the fwd1
    instance to the button somewhere farther down the timeline. Isn't
    the point of button instance names to allow you to code them
    differently on different frames but not have to create a different
    button?? Should I just create a new button??
    thank you for any insight into this matter..

    i cudn't grasp all the things that u ve written but whateva i
    ve understood based on that i can give the explanation...probably
    it ll help u ....C when u ve a button on first frame and u provide
    it an instance name on frame 1 and ur timeline spans 100 frames
    then the button will ve that instance name for those 100 frames
    until and unless u change the instance name by creating a keyframe
    sumwhere in middle and renaming it. From that keyframe onwards that
    button ll b known by the new name...
    As far as i cud understand ur problem..if u want the button
    functionality to be available only on the frame where u ve given ur
    button a name and not after that u need to create an empty keyframe
    in ur actionscript layer right after it ( for eg if u ve a button
    on frame 1 and a code defines its functionality in action layer
    frame 1 then u need to create an empty keyframe on action layer
    frame 2)..this ll make sure that after that particular frame the
    button has no actionscript targeting it...After this empty keyframe
    now u can create another keyframe in action layer ( say for eg at
    frame 50 ) to give ur button another functionality and that
    functionality will remain with the button untill and unless u
    create another empty keyframe or a keyframe with different
    code..

  • Do while loop problem

    I have a problem with do while loop. I am displaying a dialogue box where a person should enter the type of quiz he had performed. The problem is that the user should enter only the following 3 words, either "Earthquakes" or "Place" or "Animals". If the user enters any other word, he/she should be displayed wwith another message saying "Invalid". This should keep repeatinf (i.e. displaying invalid) until the user enters either of those 3 words. When a user enters one of those words it will stop diplaying "Invalid". I tried doing this, but altough it displays "Invalid" when a user enters an invalid word, it will display invalid also when a user neters the correct word. I think i have something wrong with the loop.
    This is the code:
         String player = JOptionPane.showInputDialog(null, "Enter name");
                 String type = JOptionPane.showInputDialog(null, "Enter your quiz type");
                do
                    type = JOptionPane.showInputDialog(null, "Invalid entry. Try again." );
                 while (type != "Earthquakes"  || type != "Place" || type != "Animals" );

    Yeah thats a good idea, but i'm still a beginner and i'm still new to some things. I got a problem, because altough the while loop is working correctly, however the first time i enter a word even if its correct its still displays invalid. I think that thats a property of the while loop. So can someone pls tell me how can i change this loop and use another loop that wouldn't do this. Can i use perhaps a for loop instead here? Thanks a lot.
    String player = JOptionPane.showInputDialog(null, "Enter name");
              String type = JOptionPane.showInputDialog(null, "Enter your quiz type");
                  do {
                      type = JOptionPane.showInputDialog(null, "Invalid entry. Try again." );
                   } while(!type.equals("Earthquakes") && !type.equals("Places") && !type.equals("Animals"));
                Edited by: datax on Feb 21, 2008 10:46 AM

  • Using a DAQ value in a location outside of the While Loop it is placed in

    I am writing a program that records the speed of a car and then is supposed repeat the action through the use of an actuator.  I was able to write the program to the point where I am saving the data into a .txt file and will be able to read it back out.  My problem is that I need to use a dbl value that I am calculating from the output of a DAQ Assistant block that is contained inside a while loop in another part of the program to compare current speed vs. recorded speed then output an action.  Everytime I try to draw a connection outside of the while loop, the actual value is not read outside of the loop.  I cannot put the other part of the program into the while loop because the while loop only performs every .1 to 1 second and I need the output to the actuator to be a continous string delievered to the serial port.  I also cannot create another DAQ Assistant block that reads the same port outside of the while loop.  I have thought about using a jumper to another input on the input card, but I would prefer not to use the extra space.
    So generally speaking, I'm wondering if there is a way to read a value obtained from a DAQ Assistant block outside of the while loop it is contained in.
    Thanks to anyone that can help!!!
    Travis

    Cheers,
    I am not 100% sure what your problem is but how about writing the red value into the local variable and reading it outside of the loop? Or enqueue the value into the queue and dequeue it in the other loop (Producer/Consumer Structure (Data))?
    Br,
    Jick

Maybe you are looking for

  • Processing Leavers for Employee expenses and blocking their vendor records

    Help please: Is there a set way of stopping Employee expense records in FI when an employee leaves, and putting a payment block on his/her vendor record? There is no employee status, therefore can the end dates be updated? If so, will this automatica

  • HT1379 Some keys won't work?

    What causes some of my keys not to work?

  • MODULEPOOL-TABLECONTROL

    <<Moderator message: please use a meaningful subject, and not in all CAPITALS.  Thank-you>> Hai,   goodmorning to all,this is srinivas. my problem is that i have created a module pool pgm using tabstrip control.now i need to insert table control in t

  • How to download mac osx 10.5 for powerbook G4

    how to download mac osx 10.5 for powerbookG4

  • Funny problem loading images

    Hi all, I'm currently on Safari ver 4.1.3. Previously an auction website I'm often surfing works fine, but now it has problems loading specific images. Or rather it just doesn't load the product images at all. Seems stuck as there are no indication t