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

Similar Messages

  • Help with a while loop condition

    I'm trying to write to a File. I ask the user for input, then I enter a while loop and test the condition. The loop works, but it won't stop. I've tried everything. Here is my code please help!!
    thanks
    inputline = keyboard.readLine();//read the keyboard
    try{
    while( inputline != null ){
    DiskOut.println( inputline );
    DiskOut.flush();
    inputline = keyboard.readLine();//read the keyboard again
    }//end while
    }//end try
    catch (IOException e) { 
    e.printStackTrace();
    }//end catch
    also i've tried these while loop conditions:
    while(inputline != "\n" || inputline != "\r") and the sort

    while(inputline != "\n" || inputline != "\r")The condition
    X!=Y OR X!=Z (given Y != Z)
    is always true. X will always not be equal to at least one of the values. So you'll want to use:
    while(!inputline.equals("\n") && !inputline.equals("\r"))In other words, "while inputline is not equal to either of them". Note the use of && instead of ||.
    If "keyboard" is simply a BufferedReader on top of System.in (and not your own class), the trailing line feeds and carriage returns won't even be in the string returned by readLine(). Your best bet is this:
    while(null != inputline && 0 != inputline.length())Make sure you type the two parts of that AND condition in the order above. If for whatever reason there are trailing \r and \n on the strings, you'll want to accomodate for platforms that may include both characters.
    // trim the trailing newline characters
    while(inputline.endsWith("\r") ||
          inputline.endsWith("\n")) {
       inputline = inputline.substring(0,inputline.length()-1);
    // or maybe this will work if you don't mind losing
    //  the whitespace at the beginning of the string:
    inputline = inputline.trim();Hope that helps somewhat.

  • If statement on a while loop condition

    Hello,
    I was just wondering whether it was possible to have an if statement on a while loop. Basically, I have a while loop that has the following terminating condition
    do{
    //...loop code here
    while (netError > acceptableError && learningCycle < 100000 && alive);I'm looking to introduce a boolean "ignoreMaxCycles" that basically stops the loop from taking notice of the learningCycle clause of the condition.
    do{
    //...loop code here
    while (netError > acceptableError && alive);I know it can be done repeating the two loops with an if statement governing which one is executed, but I was wondering whether there was a shorter/cleaner way of doing this?
    Thanks,
    Nick

    nickd_101 wrote:
    Hello,
    I was just wondering whether it was possible to have an if statement on a while loop. Basically, I have a while loop that has the following terminating condition
    do{
    //...loop code here
    while (netError > acceptableError && learningCycle < 100000 && alive);I'm looking to introduce a boolean "ignoreMaxCycles" that basically stops the loop from taking notice of the learningCycle clause of the condition.
    do{
    //...loop code here
    while (netError > acceptableError && alive);I know it can be done repeating the two loops with an if statement governing which one is executed, but I was wondering whether there was a shorter/cleaner way of doing this?
    Thanks,
    Nick
    do {
    while(netError > acceptableError && (ignoreMaxCycles || learningCycle < 100000) && alive)wtf ? i took 2 minutes for that ?
    Edited by: darth_code_r on Aug 29, 2008 9:21 AM

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

  • Conditional loops (while loops)

    I am using a while loop to check a digital input. I would like to send the value to a true or false box to check another digital input. The problem is that the while loop is running continuously but not giving anything out through the connection. I am looking for something like "if this do that conditional". Is there a way to set this up?

    Thanks for that suggestion. I have attached a picture of the loops as they are set up in the vi. I have taken out all of the extras to make matters simpler. The main problem is to connect loop number three to number one, so that whenever the value inside of the loop number three is true it is terminated and starts loop number one.
    Attachments:
    loops.bmp ‏470 KB

  • How to run a do-while loop on the 2nd execution after a stop on failure occurs?

    I am trying to use the Stop on Failure process model callback from the TestStand Examples.
    If a step fails within a Do-While loop and the test is terminated, the second time the test is run (continuing to the Next UUT in the process model), the condition for the do-while loop is checked first before it ever enters the loop. This is incorrect because the Do-While loop should execute once and then check the "while" condition.
    Also, If I was to stop the execution altogether and then restart the test (instead of continuing with the Next UUT), it runs the loop once, then checks the "while" condition.
    I'm not sure if I am describing this clearly enough. The execution seems to flow like this:
    Start test
    Do
    NumericTest step FAILS  -> terminate
    Next UUT starts
    While (condition is false and skips over Numeric Test step).
    So it seems that TestStand thinks it's still within that Do-While loop on the second execution and whatever runtime variables are not reset correctly.
    Is this a TestStand bug?  It happens in both TestStand 3.1 and 3.5.
    Is there any way around this?
    Thanks for any help.

    If it is what I think it is, it is a bug. Try unchecking Sequence Properties>>Optimize Non-Reentrant Calls to This Sequence and please tell me if that fixes it.

  • How to code a parallel 'for loop' and 'while loop' where the while loop cannot terminate until the for loop has finished?? (queues also present)

    I've attached a sample VI that I just cannot figure out how to get working the way that I want.  I've labeled the some sections with black-on-yellow text boxes for clarity during the description that follows in the next few sentences.  Here's what I want:
    1) overall -- i'm intend for this to be a subVI that will do data acquisition and write the data to a file.  I want it to use a producer/consumer approach.  The producer construct is the 'parallel for loop' that runs an exact number of times depending on user input (which will come from the mainVI that is not included).  For now I've wired a 1-D array w/ 2 elements as a test case.  During the producer loop, the data is acquired and put into a queue to be delt with in the consumer loop (for now, i just add a random number to the queue).
    2) the consumer construct is the 'parallel while loop'.  It will dequeue elements and write them to a file.  I want this to keep running continuously and parallel until two conditions are met.
          i. the for loop has finished execution
          ii. the queue is empty.
       when the conditions are met, the while loop will exit, close the queue, and the subVI will finish. (and return stuff to mainVI that i can deal with on my own)
    Here's the problems.
    1)  in the "parallel for loop" I have a flat sequence structure.. I haven't had time to incorporate some data dependency into these two sequential sections, but basically, I just care that the "inner while loop" condition is met before the data is collected and queued.  I think I can do this on my own, but if you have suggestions, I'm interested.
    2)  I can easily get the outer for and while loops to run sequentially, but I want them to run in parallel.  My reasoning for this is that that I anticipate the two tasks taking very different amounts of time. .. basically, I want the while loop to just keep polling the queue to get everything out of it (or I suppose I could somehow use notifiers - suggestions welcome)...  the thing is, this loop will probably run faster than the for loop, so just checking to see that the queue is empty will not work... I need to meet the additional condition that nothing else will be placed in the queue - and this condition is met when the for loop is complete. basically, I just can't figure out how to do this.
    3) for now, I've placed a simple stop button in the 'parallel while loop', but I must be missing something fundamental here, because the stop button is totally unresponsive.  i.e. - when I press it, it stays depressed, and nothing happens.
    suggestions are totally welcome!
    thanks,
    -Z
    Attachments:
    daq01v1.vi ‏59 KB

    I'd actually like to add a little more, since I thought about it a bit and I'm still not quite certain I understand the sequence of events...
    altenbach wrote:
    zskillz wrote:
    So i read a bit more about the 'dequeue element' function, and as I understand it, since there is no timeout wired to the dequeue element function, it will wait forever, thus the race condition I suggested above can never happen!
    Yes, you got it!
    As I've thought about it a bit more, there's a few things that surprise me... first, the reason the 'dequeue element while loop' errors is not because there's nothing in the queue, it's becaues the queue has been released and it's trying to access that released queue...   However the problem I have is this --- Even though there's no timeout wired to the dequeue element, I still would think that the while loop that contains it would continue to run at whatever pace it wanted -- and as i said before.. most of the time, it would find that there is nothing to dequeue, but once in a while, something is there.  however, it seems that this loop only runs when something has been enqueued.  the reason I say this is illustrated in the next code sample MODv2 that's attached below.  I've added a stop button to the "queue size while loop" so the program runs until that is pressed.  I've also added a simple conditional in the "dequeue while loop"  that generates a random number if it a button is pressed... but this button is totally non-responsive... which means to me that the "dequeue while loop" isn't actually continuously running, but only when an element is added to the queue.  this still seems almost like the 'dequeue while loop" waits for a notifier from the queue telling it to run.  can you explain this to me? because it is different from what I expect to be happening.
    rasputin wrote:
    I tried to open your VIs but it doesn't work. LV
    is launched, the dialog box (new, open, configure...) opens and then...
    nothing. Not even an error message. I guess it isn't a problem of LV
    version or a dialog box would appear saying this. Could you, please,
    send a image of the code?
    Thanks,
    Hi Rasputin, I'm using LV8.  I assume that was your problem, but who knows.  I've attached a pic of of altenbach's solution since it's what I needed.
    thanks
    -Z
    Message Edited by zskillz on 10-20-2006 11:49 AM
    Attachments:
    daq01v1MODv2.vi ‏63 KB
    daq01v1MODpic.JPG ‏116 KB

  • How fast does a while loop executes

    hi how fast does a while loop actually checks its condition??
    depending on the processor speed??
    anyone??

    Sorry I write that wrong,
    heres how it should be:
    public class whileLoop{
    int time, time2;
    time = System.currentTimeMillis();
    public timer()
    while //watever//{
    time2 = System.currentTimeMillis();
    time2 = time2 - time;
    system.out.println(time);
    class use{
    whileLoop a = new whileLoop();
    public void main(String args[]){
    a.timer();
    }

  • Ai read in while loop

    I am acquiring data from a DAQ e series card. i intialized the daq by using AI config out side while loop . i used AI start and AI read in while loop . iam acquiring data from 5 channels. the buffer size ia 1000 and so is the scan rate in AI start.I want to save the acquired data in the file. i am also displaying data o n chart. every thing is working fine. my problem is i want to save 500 points in one seconds. for this i changed the while loop execution time by using waint until multiple sec VI and assign it 10  i was expecting that now iwll save more data point in file as now loop will execute more fast but it does not happen like this. is there any way to minimize the executing time of whil loop.i checked if i deleted AI start and AI read then loop execute very very quickly. should i place AI start and AI read out side loop but then how will it acquire data contiously. I m attaching gif file of the protion of my VI .any suggestion?
    Attachments:
    myVi.GIF ‏72 KB

    I was working quickly, and from memory, so my apologies for errors or non-clarity in my previous post. :-(
    The AI START VI, should be used OUTSIDE the loop, since you only want to START the task ONCE.
    When the task is complete (your WHILE loop is done), then call the AI CLEAR task to clean up (ONCE).
    If you set the NUMBER OF SCANS TO ACQUIRE input to AI START to zero, that has a special meaning: acquire data indefinitely. It will not stop on it's own (assuming no errors occur), you have to explicitly stop it.
    If you do this, you have to read the data often enough to avoid buffer overflow, which means the incoming data is filling up the buffer faster than you're emptying it.
    I have attached a picture of the general idea. If you really want to use the CPU efficiently, then consider the shift-register idea in the picture - you process on batch of data WHILE the next batch is coming in. If you want a simpler solution, forget the shift-reg, and process it directly after reading it. If your buffer is twice the size of your processing size, you'll be OK.
    Message Edited by CoastalMaineBird on 09-14-2005 07:45 PM
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    DAQExample.png ‏16 KB

  • I have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    Hi fais,
    Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
    You can replace the inner for loop with a while by doing the following.
    1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
    2) Make sure the tunnels you where indexing on with the for loop are still indexing.
    3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
    4) Wire the output of the array size into the new while loop.
    5) Set the condition terminal to "stop if true".
    6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
    7) C
    reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
    8) Drop a "less than" node inside the inner while loop.
    9) Wire your iteration count into the bottom input of the "less than".
    10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
    Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
    I will let others explain how to takle this task using the "case solution".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • While loop problems

    hey guys,
    i made a program that counts any system with single character values (binary, ternary, octal, decimal,...etc) I am asking the user to input a starting point to count from and a stoping point to stop at. It starts from the correct place but does not stop.
    For some reason it is ignoring my while loop condition. anyone got any idea why this would happen?
    import javax.swing.*;
    import java.util.*;
    class Counting
         public static void main(String[] args)
              String input,start,stop,s;     
              int spaces;
              input = JOptionPane.showInputDialog("Enter number of spaces.");
              spaces = Integer.parseInt(input);
              s = JOptionPane.showInputDialog("Enter counting symbols in sorted order.");
              start = JOptionPane.showInputDialog("Enter the stating number. (" + spaces + " characters).");
              stop = JOptionPane.showInputDialog("Enter the number to stop at. (" + spaces + " characters).");
              StringBuffer num = new StringBuffer(start);
              int lspace = spaces - 1;
              int i,j;
              String k,z;
              System.out.println(num);
              while(num.equals(stop)!=true)
                   k = Character.toString((num.charAt(lspace)));
                   z = Character.toString((s.charAt(s.length()-1)));
                   if(k.equals(z)==false)
                        i = s.indexOf(num.charAt(lspace));
                        num.setCharAt(lspace, s.charAt(i+1));
                   else
                        num.setCharAt(lspace, s.charAt(0));
                        lspace--;
                        i = s.indexOf(num.charAt(lspace));
                        num.setCharAt(lspace, s.charAt(i+1));
                        lspace = spaces - 1;
                   System.out.println(num);
              System.exit(0);
    }

    i got it to work.
    here is the if anyone is interested. Thank for the help!
    import javax.swing.*;
    import java.util.*;
    class Counting
         public static void main(String[] args)
              String input,start,stop,s;     
              int spaces;
              input = JOptionPane.showInputDialog("Enter number of spaces.");
              spaces = Integer.parseInt(input);
              s = JOptionPane.showInputDialog("Enter counting symbols in sorted order.");
              start = JOptionPane.showInputDialog("Enter the stating number. (" + spaces + " characters).");
              stop = JOptionPane.showInputDialog("Enter the number to stop at. (" + spaces + " characters).");
              StringBuffer num = new StringBuffer(start);
              int lspace = spaces - 1;
              int i,j;
              String k,z;
              System.out.println(num);
              while(!num.toString().equals(stop))
                   k = Character.toString((num.charAt(lspace)));
                   z = Character.toString((s.charAt(s.length()-1)));
                   if(k.equals(z)==false)
                        i = s.indexOf(num.charAt(lspace));
                        num.setCharAt(lspace, s.charAt(i+1));
                   else
                        while((Character.toString((num.charAt(lspace)))).equals(z)==true)
                             num.setCharAt(lspace, s.charAt(0));
                             lspace--;
                        i = s.indexOf(num.charAt(lspace));
                        num.setCharAt(lspace, s.charAt(i+1));
                        lspace = spaces - 1;
                   System.out.println(num);
              System.exit(0);
    }

  • Why does a sequence structure execute if a while loop is to the left of it?

      I have a while loop in a case structure whose boolean is wired to a sub vi.  To the right of this structure I have a sequence that executes regardless of the while loops condition.  I assumed that the program would not continue to the case structure until the while loop stopped.  Then it would proceed to the case structure.
    Thank You

    jemengineering wrote:
      I have a while loop in a case structure whose boolean is wired to a sub vi.  To the right of this structure I have a sequence that executes regardless of the while loops condition.  I assumed that the program would not continue to the case structure until the while loop stopped.  Then it would proceed to the case structure.
    As others have mentioned, you have to familiarize yourself with the core idea of dataflow programming. One of the great powers of LabVIEW is the fact that things can occur in paralell unless there is data dependency.
    A good start would be the LabVIEW beginners online tutorial:
    http://www.ni.com/swf/presentation/us/labview/aap/default.htm
    The quiz #1 on slide 11 deals with the above issues. Try to answer it. 
    In your particular case, you need to force execution order. This can be done by creating a data dependency (preferred) or by the use of a sequence structure. You could e.g. create a 2-frame flat sequence and place the loop in the first frame and the case structure in the second frame.
    The picture shows a few scenarios for comparison. Can you spot the differences?  Understanding dataflow is crucial for writing any LabVIEW program.
    Message Edited by altenbach on 07-31-2006 06:49 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ExecutionOrder.png ‏19 KB

  • Quit while loop in event structure

    Hello,
    I used event structure in my application and I would like to quit a while loop in an event structure when I pressed a control. But I have a problem because I'm in the event.
    Do you have a solution.
    Sam.
    Attachments:
    Problem.vi ‏34 KB

    Hi,
    connect a true constant to the While loop conditional terminal in the STOP event case.
    See your example modified.
    Good luck,
    Alberto
    Attachments:
    Problem[2].vi ‏35 KB

  • Writing a file for prescribed amount of time in a while loop after the triggering condition is met

    Hello Guys,
    I am trying to program an application in which if the trigger condition is met it should start to write the file.
    I was able to do that, but if I want it to be written for certain amount of time, and once the trigger condition is met, it should continue to write the files for prescribed amount of time. I was not able to do this. The file name should also be updated accordingly.
    I tried to with some options by keeping the creation of the file outside of the loop, if I do that then if the trigger condition is not met it will stop writing and I dont want that, as once the trigger condition is met it should be true thereafter.
    So I cant keep any thing outside the while loop, bcaz then it checks the condition of the shift register for the trigger and I have it as a false constant.
    I am attaching my application which is kind of mess and I have written in the application where I am having problems. For every iteration of while loop it makes a new file, and i dont want that, I want to write specific amount of time data to the each file.
    Please take a look at my code and help me in solving the problem. Any insights and examples on how to do this thing will be a relief to me.
    Thanks in advance.
    Regards,
    Nitin
    Attachments:
    PXI_4462_Sync_and_Stream_trigger.zip ‏192 KB

    what i am saying is to keep track of how much data you have written and whenever you need to make a new file you make 1.
    here is a vi that i just made that should show you. let me know if you need any help understanding it.
    Attachments:
    new file exemple.vi.zip ‏21 KB

  • How to call sub VI and close the main VI in while loop and sequence condition

    Hiya,
    I have a problem with the while loop and the sequential condition in placed together i.e while loop as Global and sequential condition as local (i.e inside the Global loop). For example,when calling the sub vi from the main vi (main vi as main menu and sub vi as sub menu.)My problem is I can't run my sub menu when the particular icon is pressed through the main menu and only the front panel appears. My concerned was if possible the sub menu is activated in few second then jump back to the main menu again (analyze through the diagram).So, I don't know what should I need to do. If possible, please advice me how to encountered that particular problem.
    Thanks!

    Go to your block diagram of your main menu, then click on the "Hightlight Execution" it is something like a bulb. then you execute your vi. then LV will show you all your data flow.
    When you feel sad, laugh

Maybe you are looking for

  • RTF Templates and report file (.xdo)

    Hi all, I use Oracle report and I would like to migrate from that software to Oracle BI Publisher. During my tests, I encountered various problems like the following: I create my report (.xdo file is generated) in development with one RTF template. I

  • UTL_SMTP - Error while using Cc

    Hi All, I have got a issue regarding sending mails via pl/sql. Unable to add an mail id using Cc. The procedure looks something like this. CREATE OR REPLACE PROCEDURE test_mail is mailhost VARCHAR2(100) := 'GASVREXC01'; conn UTL_SMTP.CONNECTION; crlf

  • IPod 4th Gen. Stuck on AC ADAPTER icon

    So, I have a 20GB iPod 4th Gen and it was working fine. Haven't used it much over the last few years. However, all was operational. Recently pulled off old songs to transfer back to my Mac, everything was visible (hard drive and songs in iTunes) and

  • Deprec. area data can be changed despite view authorization

    Hi, Users with Asset view '03' (ie authorization to change master data for only tax depreciation areas-10,11,13 & 40) are able to change values in asset master for all deprecation areas. I applied note 1316246 and in user role restricted the AA_VIEW

  • SMTP Authentication fix?

    I was looking for a way to let our mail server relay mail through our ISP. Everything I found said use the terminal and create a file with our username and password in etc/postfix/sasl_passwd Then in SA go to mail->settings->relay outgoing mail throu