Problem writing condition of a while loop

I'm receiving an error when attempting to compile my class.
while(numItems != 1 || 2 || 3) (numItems is an integer variable)
Basically, using the Scanner class, I request an integer input from the user, and that input needs to be either 1, 2 or 3, so I have included the while loop as a validation tool, so that whenever the user's input is NOT 1 or 2 or 3, the system prints out an error message and the user has to reenter. However, the code above is highlighted when I compile, and the error description states that I cannot use the || operator for the int data type. I wasn't sure if the OR operator was two || pipes or one, but I receive the same error regardless.
Is there a way around this?
Thank you.

ryanz0r wrote:
I'm receiving an error when attempting to compile my class.
while(numItems != 1 || 2 || 3) (numItems is an integer variable)
Basically, using the Scanner class, I request an integer input from the user, and that input needs to be either 1, 2 or 3, so I have included the while loop as a validation tool, so that whenever the user's input is NOT 1 or 2 or 3, the system prints out an error message and the user has to reenter. However, the code above is highlighted when I compile, and the error description states that I cannot use the || operator for the int data type. I wasn't sure if the OR operator was two || pipes or one, but I receive the same error regardless.
Is there a way around this?Hi, Ryaz0r.
In conjunction with Encephalopathic's syntax question for your valid boolean expression, you'll also have to replace the || operators with the && operators to achieve your described condition.
-- L. James
L. D. James

Similar Messages

  • Writing text file in while loop

    Here is my question about writing text data to a file in a while loop...worded best I can.
    I have an Init case where I have the user choose a file path and name. I take the ref out and then I have data that is being written to the file. The loop will take 40,000 pieces of data write them to the file and go back to the get data case to collect another 40,000 data points. But when I open the file, I only get a file as big as 430KB. I'm not sure but can somone show me an example of pulling analog data from a DAQ Assist, doing a calculatoin on it, writing it to a file and repeating that by adding it to the same file at the end of the previous data?
    Solved!
    Go to Solution.

    Take a look at the attached VI's.  Did you have your data set to append?  This could be your problem.
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
    Attachments:
    Save Data SM.vi ‏15 KB
    File Path Prompt.vi ‏15 KB

  • Problems with opening file with while loop

    Greetings everyone,
      This is probably a quick question, but I am familiarizing myself how to open data files in Labview. The attached code works if you enter a file from the folder button on the front panel. However, if the path is blank and you hit the run (arrow) button, a dialog box comes up and asks for the file.
       I select the file, but the dialog box keeps coming up. I think this has something to do with my while loop. Can anyone tell me where I am going wrong?
      Thanks!
       TheLT
    Solved!
    Go to Solution.
    Attachments:
    ReadingfromData.vi ‏27 KB

    TheLT,
    1. crossrulz was right. The Read FromSpreadsheet File.vi opens and closes the file each time it is called. If no file path is present at the input when it is called, it will pop up a file dialog.
    2. LabVIEW uses a dataflow paradigm. In your program the effect of this is that the File path control is read almost immediately when the program is started and never again after that. So, if the program is already running when the file is selected in that control, the new value is never read and the value (empty) in the control when the rpogram started is used.
    3. The fix is to use an event structure with a file path Value Changed event to detect when the control has a value entered and then read the file.
    4. Sequence structures obscure code, make it difficult to modify and extend code, and can almost always be eliminated by effective use of dataflow.  Local variables should not be used just to pass data around.  Wire is always the best way when possible. In your program adding a few wires allows elimination of the sequence structure and the local variables.
    5.  Your graph loop should have some kind of delay or wait.  No need for it to run as fast as the processor will allow - and to hog all the CPU time - to repeatedly put the same data onto the graph.  This is another place where an event structure is appropriate. Only update the graph when the X-Axis or Y-Axis selections have changed. Note: Accepted best practice is to use only one event structure in a program, although there are a few advanced cases where multiple event structures are appropriate.  You only need one.
    6. If the slected file does not contain the "endheader" string, the program will never stop.  Add a test for EOF to stop the program if the End of File is reached without finding the flag.
    Lynn
    Attachments:
    ReadingfromData.2.vi ‏27 KB

  • Problem writing inverse for XOR encoding loop

    Hi,
    I'm trying to create an inverse to the following Java function in Ruby.
    public static void encXORPass(byte[] raw, final int offset, final int size, int key)
              int stop = size-8;
              int pos = 4 + offset;
              int edx;
              int ecx = key; // Initial xor key
              while (pos < stop)
    // get 4 bytes from raw into an int
                   edx = (raw[pos] & 0xFF);
                   edx |= (raw[pos+1] & 0xFF) << 8;
                   edx |= (raw[pos+2] & 0xFF) << 16;
                   edx |=  (raw[pos+3] & 0xFF) << 24;
    // do things
                   ecx += edx;
                   edx ^= ecx;
    // put the xor'd int back into raw
                   raw[pos++] = (byte) (edx & 0xFF);
                   raw[pos++] = (byte) (edx >> 8 & 0xFF);
                   raw[pos++] = (byte) (edx >> 16 & 0xFF);
                   raw[pos++] = (byte) (edx >> 24 & 0xFF);
    // store the final key in the last 4 bytes of raw
              raw[pos++] = (byte) (ecx & 0xFF);
              raw[pos++] = (byte) (ecx >> 8 & 0xFF);
              raw[pos++] = (byte) (ecx >> 16 & 0xFF);
              raw[pos++] = (byte) (ecx >> 24 & 0xFF);
    }I'm basically walking through the same loop backwards, but for some reason my code doesn't currently completely decode the data. By "completely" I mean a few bytes into the loop it actually converges to the correct values, but not at the beginning. I've been trying to figure out why for weeks and I'm not making any progress so thought I'd post it here.
    Here is an example of a correct decoded sequence, followed by my incorrect decoded sequence (yes they are different if you go far enough to the right):
    00854130CE21C60000BD7F26062B09315C26E24D80378DD9FB568AF57C765D9A2C90A6B0124EA36014881A48A185B44FC9A6D922D03E1F91FB0468819721E639E21AC617D44D3A7E952C2211EDB36ABCFC81B51E8AC205DCC750D7EA0C18F49CE8A119A8DA67591C97B5B7D6C9EF61F7F25E6EBDC10EA0BAA1F388D3210198B1A66B1E09437E3AA2204E95DD29FC9CC37720B6AD97F7E0BD0731C3725F3B6566FEC6F2CD5473468F2700E8436B286DACD9FE6C8B9F9EADDF
    00854130CE21C60000BD7F26062B09315C26E24D80378DD9FB568AF57C765D9A2C90A6B0124EA36014881A48A185B44FC9A6D922D03E1F91FB0468819721E639E21AC617D44D3A7E952C2211EDB36ABCFC81B51E8AC205DCC750D7EA0C18F49CE8A119A8DA67591C97B5B7D6C9EF61F7F25E6EBDC10EA0BAA1F3883321019841A66B1EF1437E3ADE204E95C329FC1CCC772056AA97F71CBE07313C735FBB9A66FE06EDCD5493418F271FE8C3EBE86CEC41A6A4B69F9EADDFAny insight appreciated,
    Cheers.

    bensum wrote:
    Sorry, I didn't realise posting in this forum and any other forum were mutually exclusive events. Oh, you've posted in both? So people can waste their time repeating what others have already said. Nice.
    I haven't posted my code because it's Ruby like you say and I wouldn't expect people here to know or correct Ruby.Then why post here at all? If your code doesn't work, it's a bug in your code. It's rather hard to correct it without seeing the code. If you want help here, you should try to write the code in Java. If it works, great, translate it to Ruby, and if that doesn't work, post in the Ruby forum. If you can't get the Java version to work, post here with details.
    It seems to me that the problem is more about a property of this algorithm that I don't know about than my particular code (because it converges far down to the correct values). I don't see how it could converge far down to the correct values, without being correct at the beginning, that's the problem. Anybody any ideas?I have an idea that there's a bug in your code and that the best way to diagnose it is to see the code. :-)

  • Problem aggregating sums in a while loop

    I'm relatively new to java. In my latest project, one part of the project is to translate this equation:
    [http://img.photobucket.com/albums/v281/molotov001/rt01.jpg]
    into java.
    Retaining what little knowledge I have of Calculus, this basically means that I should start with i=0, run through that function and increase i by 1 until it reaches a final number yearsWorked-1, all the while adding the functions with respect to different values of i.
    This is what I have so far
    int i = 0;
    double aime = (income * Math.pow(1.02, i) * Math.pow(1.04, (year - incYear - i)))/420;
              while (i <= (yearsWorked-1))
                   ++i;
                   double aime1 = (income * Math.pow(1.02, i) * Math.pow(1.04, (year - incYear - i)))/420;
                   aime = aime + aime1;
              }I know this is wrong because it outputs a number that is incorrect, but not by much. Also assume that income, incYear, yearsWorked and year are already defined doubles.
    Any help you might be able to offer is greatly appreciated.

    {color:#000080}Use an integer type like int or long for yearsWorked. When using double, yearsWorked - 1 may not be the exact value you expected.
    Why do you need a double value for a variable that you compare integrally anyhow?
    db{color}

  • While loop condition check

    Dear All,
    attached is an NI that does the following.
    1. The user inputs a frequency and amplitude range to drive a speaker.
    2. A laser displacement sensor measure the speaker displacement, checks if it is in the desired range, and jumps on to the next frequency, if its not in the desired range it tries another drive voltage.
    The program works fine, the problem is, is that the while loop checks the condition in the beginning or the middle of the loop, therefore if it is in range instead of stoping at that particular amplitude and frequency, it goes to the next amplitdue before going to the next frequency. Since at the begining of the loop execution the condition was different that in the middle.
    How can I force the while loop to read the condition only after the sequence inside has completed.
    Thank you
    Ala
    Attachments:
    AmpFinder.vi ‏431 KB

    Dear All,
    I think this fixes the problem
    Cheers,
    Ala
    Attachments:
    AmpFinder.vi ‏431 KB

  • Editing While Loop Conditions hangs JDeveloper 10.1.3

    Hi Guys,
    Having a strange problem when I tried to edit the condition in a while loop after it was created and set first time. The IDE just hanged when I tried to open the expression builder and after a while, nothing happened, the expression builder didn't show up.
    I went and deleted the condition by editing the source, basically made condition from:
    <while name="While_1"
    condition="bpws:getVariableData('inputVariable','payload','/client:WhileLoopTesterProcessRequest/client:input')&lt;10">
    to
    <while name="While_1"
    condition="">
    Switched back to graphics mode, the expression builder opens up normally.
    I understand that we are evaluation a Developers Preview, so just wanted to bring this to the notice of the developers.
    Any solutions before the Production release?
    Regards,
    - Soumen.

    Hi Willian,
    Did you set up your "Model" Project to use the JDK 1.4 and rebuild the application ?
    See " [Deploying to Application Servers That Support JDK 1.4|http://tinyurl.com/lfc6kc] "
    Regards,
    Didier.

  • Problem with two parallel While loops

    I have a serious problem with controlling two parallel While Loop. Here is the deal:
    I have written a VI to send a series of commands called Cycle through Serial Port to a custom hardware. One of these commands is setting motor pressure by sending it's command and changing it's voltage. After setting desired pressure I have to read and control motor pressure, again through serial port in a parallel loop. There is a Pressure Sensor in system and I can obtain current's motor pressure by sending a command and receiving pressure value. In the first While loop I send some commands to hardware including Pressure Setting Command trough a state machine. In the second While Loop I read pressure value and then decide to increase motor voltage or decrease  it. Now the problem is in communicating these two loops. In cycle after "Init" state when state reaches "Pressure 2 Bar" motor voltage will increase. Meanwhile I have to control this voltage in parallel While Loop. As you can see I used Local Variable to communicate between these two loops. The problem is that loops are not synchronized. Specially when I switch to "Pressure 3.8 Bar" state during cycle running control loop (second while) is still working based on "Pressure 2 Bar" state not 3.8 bar. Because of this motor pressure goes to 3.8 bar for a sec (becuase of  "Pressure 3.8 Bar" state) and comes back to 2 bar (because the second while still has not gotten that new state,most probably cause of all the delays in the loop)  and after couple seconds it goes back to 3.8 bar.
    I really don’t know what to do. Is there a way to fix this? Or I should consider a better way to do this?
    I went through Occurrence Palette but couldnt figure out how to embed that in the VI. 
    Sorry for my poor English. I attached VI and it's subVIs as a LLB file. I can explain more details if somebody wants. 
    Attachments:
    QuickStartCycle.llb ‏197 KB

    I make it a point to NEVER have a WAIT function inside a state machine.
    It sort of defeats the purpose, which I define as "Examine current state; decide whether you've met the conditions to advance to another state, then get out".
    For example, I have a single state machine VI controlling four identical instruments, via TCP connections.
    For some functions, that means issuing a command, waiting 60 seconds, then reading results.
    If I waited INSIDE the state machine, then it's tied up waiting on one device and cannot handle any others.
    Not a good plan.
    To handle this, I have a loop which calls the state machine.  After issuing the command, the state goes to "Waiting on Response", and there is a target time of 60 seconds from now.
    It's called over and over in that state, and each time merely compares NOW to the target time.  If NOW is past the target, then we read the results.
    the state machine can tell the caller when to call back; that's how I distinguish between an urgent need and nothing-to-do.
    By having the CALLER do the waiting, instead of the state machine itself, the state machine is free to handle another device, or do something else on the same device.
    You should be calling the state machine over and over and over anyway.  So, have the state machine "control the pressure" on every call, and THEN examine whatever state it's in.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Can not pass data after while loop

    Hello.
    I have created a VI for my experiment and am having problem passing data outside a while loop to save on an excel file. The VI needs to first move a probe radially, take data at 1mm increment, then move axially, take data radially at 1mm increment, then move to the next axial position and repeat. It would then export these data to an excel file. The VI is a little complicated but it's the only way I know how to make it for our experiment. I have tested it and all the motion works correctly, however I can not get it to pass the data after the last while loop on the far right of the VI where I have put the arrows (Please see the attached VI ). Is it because I'm using too many sequence, case, and while loops?  If so, what other ways can I use to make it export data to the excel file?
    Any help would be appreciated. 
    Thank you,
    Max
    Attachments:
    B.Dot.Probe.Exp.vi ‏66 KB

    Ummmm .... gee, I'm not even sure where to begin with this one. Your VI is well .... ummmm... You have straight wires! That's always nice to see. As for everything else. Well... Your fundamental problem is lack of understanding of dataflow programming. What you've created is a text program. It would look fantastic in C. In LabVIEW it makes my heart break. For a direct answer to your question: Data will not show up outside a while loop until the while loop has completed. This means your most likely problem is that the conditions to stop that specific loop are not being met. As for what the problem is, I don't even want to start debugging this code. Of course, one way to pass data outside of loops is with local variables, and hey, you seem to be having so much fun with those, what's one more?
    This may sound harsh, and perhaps be somewhat insulting, but the brutal truth is that what I would personally do is to throw it out and to start using a good architecture like a state machine. This kind of framework is easy to code, easy to modify, and easy to debug. All qualities that your code seems to lack.
    Message Edited by smercurio_fc on 08-17-2009 10:00 PM

  • Beginner Question: Won't execute index to nested while loop

    Problem:
    I have a nested while loop inside a for loop. The for loop runs over and over from 0 to 587. I want the while loop to only execute when the for loop hits 587 by means of a continue condition which is on when 587 = [ i ], the for loop iteration number. However when I try to change the value sent to the while loop from 588 none of the probes execute. This is bad because the index only runs from 0 to 587 and never equals 588.
    Context:
    This is for real time video analysis. Trying to convert a 658 x 492 color video feed frame by frame into low resolution grayscale video. With this index error the output is currently the top left 1/4 of the image, repeated in a 2x2 grid on the image display.
    The VI is attached. I'm very appreciative of your thoughts on this.
    Attachments:
    Bin.vi ‏237 KB

    The for loop is responsible for processing a frame. At the completion of the execution of [ i ] from 0 to 587, the replace array VI outputs the final product of the frame. So every time [ i ] = 587, the replace array VI needs to send its array to the arraytoimage, which in turn must send the image to the image display.
    I got rid of the while loop and replaced it with the case structure. 
    Maybe the problem is with the false case of the case structure? I want to continue outputting the same image for the next [0, 586] each time after it sends an updated image on the [ i ] = 587 iteration.
    Attachments:
    Bin.vi ‏238 KB

  • How can I opearate indicator outside while loop?

    I do small program, I have many while loops and I want to connect wire (in my application) from each loop to AND gate then to another while loop, but how can I operate these wires to agree with the change of my application inside while loops.
    If not clear :
    In another words, suppose I want to operate indicator ouside the while loop. How can I operate indicator outside while loop, so when my application become TRUE (inside while loop) the indicator will be ON (outside while loop) and when my application become FALSE(inside while loop) the indicator will be OFF (outside while loop).
    Help me if you have any idea please..........................

    Hi Rammo,
    For the wire to carry the boolean condition from the while loop to an 'and' gate outside, the while loop must stop running
    If you want the while loop to keep on running and still pass a boolean value to a destination outside the while loop, use any one of these: property nodes, global or local variables.
    i am still not clear as to what you intend to say by this sentence
    " I want the wire that comes out from the while loop will become TRUE if it in my application is TRUE inside while loop and the opposite is true. Because I want to connect the wire that comes out from while loop to AND gate than to another application"
    plz tell me if the first part of this mail of mine answers your doubt or do you need more information?
    regards
    Dev

  • Capturing of time taken by a while loop in bpm

    Hi ,
    I have a busniess process ,and my receive step is defined in a while loop.
    so it starts with a while loop.
    I want to keep a condition on the while loop that it should receive the messages only for a period of 1 hour ,and if it exceeds this period it should end up the process triggeringa mail.
    I mean to say if there are 12 records to be processed through the while loop ...and if I receive only 11 records ..it will be waiting for that final record in an infinite loop ..so I dont want that ...instead if the total no of records are reached then it should move forward ..If it is waiting for the missing records for an hour ..I should stop the process and trigger a mail to the queue monitor saying that record is missing...I have finished the process without this processing time condition successfully..
    I am new to XI and I dont have any idea on how to capture this processing time of while loop.
    can some one please help me out in this issue...
    Thank you in advance...

    Hi Latika,
    Yeah I understand we can go with fork but why I am going with this is ,I have already designed a Payload dependent loop ,by using while loop.so it makes my job simple ...
    Now I am converting it to time dependent loop,so only the final question I have is...In the time dependent loop documentation ..they have taken it as infinite loop and only kept the time limit in the deadline branch...so when the deadline reaches they trigger something.
    If you go to the documentation of time dependent loop(http://help.sap.com/saphelp_erp2005vp/helpdata/en/08/16163ff8519a06e10000000a114084/content.htm) ..they took the infinite loop...in this loop if I mention the counter ..and if this record count triggers before the time limit...it should come out of the block...would it work this way ?
    Thanks a lot...

  • Stop syncronization of 2 while loops

    Hello all!
    Now in my project I got a serious problem. I have 2 while loops. One (loop 1) keeps receiving UDP messages
    from an external device and send a cetain type of message to another while loop (loop 2). The cycling time of 1st loop is
    300ms (it receives a UDP message every 300ms), the cycling time of the 2nd is 30s (30s is the receiving period of the certain type
    UDP message sent by loop1, and I used a notifier to transmit this message to loop 2, so the cycling time of second loop is 30s).
    At last when the num of the certain type of UDP messages received reaches 4, I want both loops stop, so as the program. However,
    at last both loops stopped but the program no!
    I'm quite sure it's the problem of the 'stop' of 2 loops, cuz when I don't use the notifier, not to control the cycles of the loop 2,
    at last both of the loops stop and the program could stop. But with the control of cycles of loop 2 (I mean the loop passes on cycle
    when receiving the certain type of message from loop 1), the whole program doesn't stop when both loops stop.
    So in this case, 2 loops with data dependency run with different cycling time, is it possible to syncronize the stop, in order to
    stop the whole program when both loops stop. Thanks in advance!
    Chao

    Hello Mister!
    I'm not sure in which way I could show you better my code, since the main vi contains tens of subvi.
    This pic doesn't show everything. I should explain that the higher loop is loop one which is receiving UDP
    message and send a certain type of UDP message to the lower loop.
    If you have a better idea about showing my code better, please tell me. Thank you
    Attachments:
    Immaginelabview.JPG ‏225 KB

  • How to print an array out a while loop?

    Hi all,
    I'm very new with Labview (6h of Practice) and I meet a problem.
    I create a while loop in which a read the first characters of each line of three files and put it in an 2D array (3 rows and 50 lines).
    My goal is to print this array on the VI's panel in a Table or in a Multicolon Listbox. How to do this? In the While loop or out?
    I use Labview 6i.
    Thanks for your help

    Hi,
    I don't see any problems. I suppose that you can get a 2D array of strings from files.
    Now there are three solutions.
    1. Use of Arrays.
    Right-click on the wire with your 2D array and select "Create->Indicator" from pop-up menu. Now you have a 2D array on the front panel which will show you your data.
    2. Use of Tables.
    Select table control from "Controls->List&Tables". Paste it on the front panel of your vi. Right-click on it and select "Change to indicator" from pop-up menu. Then wire this indicato to your 2D array in the block diagram.
    3. Use of Multicolumn listboxes.
    Paste the multicolumn listbox to the front panel. On the block diagram right-click on it and select "Create->Property node" from pop-up menu. The property node of your control will appea
    r in the diagram. Right-click on it and change property to "Item Names" By selectring "Properties->Item Names" from pop-up menu. Now Right-click on the property node once again and select "Change to write" or "Change all to write" to toggle your property into write mode. Then wire your 2D array to this property node.
    The example is attached.
    Good luck.
    Oleg Chutko.
    Attachments:
    Tables.vi ‏26 KB

  • To count the number of while loops, do you just have to attach a DBL indicator to the little i box in the while loop of the program?

    I have just followed an example in a book to count while loops and was just want to make sure I havent missed something simple. My program is attached
    Solved!
    Go to Solution.
    Attachments:
    second attempt.vi ‏45 KB

    Hi Ssteel,
    Just some additional observations/tips on your code...
    1. I notice that you have a standard stop button going into a "run if true" stop condition of the while loop. In this cercumstance it is common to have the stop condition set as "stop if true". You can change this by right clicking the stop terminal and enabling the "stop if true" property. Obviously, it somewhat depends on your design preferences.
    2. If you have any issues with the application, perhaps you notice that it is taking over your processor resources, you should add some execution timing into the while loop. You will find the timing functions in the block diagrams functions palette (programming > timing). The Wait (or "wait until next ms") functions will provide your application with "down time", which means that the processor can execute other tasks.
    3. To elaborate what MikeS81 correctly stated, insert an incriment before the numeric indicator as shown below to get the actual number of cycles (i.e. the count terminal of the "while" and "for" loops are 0 indexed). Also note that I have changed the representation of the count to interger (blue). You do not need floating point precion when displaying the inciment count, at a while loop can only execute a "whole number" of times.
    I hope this has been useful to you Ssteel.
    Thanks for your post,
    Rich R
    Applications Engineer
    National Instruments UK & Ireland

Maybe you are looking for

  • WRT1900AC ftp setup

    I have an external drive connected via eSATA and I can access it from File Explorer.  But what is the full path if I were to have a piece of software access the drive?

  • How to install an operating system on your hard disk,

    So when I try to start my laptop a black screen comes up with: Boot Device Not Found Please Install an operating system on your hard disk. Hard disk (3F0) F2 System Diagnostics For more information, please visit: www.hp.com/techcenter/startup Someone

  • Macbook pro keeps freezing after updating to Maverick

    my 1 year old macbook pro keeps freezing after i updated from mountain lion to maverick. all the time i had mountain lion i can remember maybe once where my mac froze. now, it froze probably 5 times in the last 5 days. how can i fix this, or better s

  • Can't Mount Xsan....

    Ok so I'm having a bad day.... I'm was adding an addition RAID to the Xsan we have here... I set up the array's the way I was told at first... Then they wanted more storage and less redundancy... So I took the LUNs out of two new pools I had made...

  • RV042 Failover does not work properly in certain WAN1 signal condition

        Our RV042 has cable modem in WAN1 and ADSL in WAN2; it is set in smart link backup mode. In certain cases of WAN1 signal loss, RV042 seems not to detect this condition. Consequently it does not switch automatically to WAN2. One way to get it to s