Stopping a while loop inside a while loop

Hello,
I have a while loop which is inside a while loop which houses my enetire application, When stopping the inner while loop portions of my outer loop stop working, How do I setup the inner while stop that it will not interfeer with the outer while loop?
Thanks,
Gil,

It sounds like he is using a simple archetecture.  But switching to a different archetecture may not be necessary.  Simply because it doesn't work, doesn't mean scrap the whole thing and start over.  He's got a bug and needs to fix it.  Is it the best archetecture to use, absolutely not, but simple or general archetectures can be effective based on the application.
Post your VI so we can take a look and give you some pointers and suggestions for improvement.
Reese, (former CLAD, future CLD)
Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home

Similar Messages

  • 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 inside a timed loop

    Hi everybody!
       I'm using:
           - LV 7.1 + RealTime;
           - compactFieldpoint;
       I've noticed a strange behaviour, when I put a while loop inside a timed loop.  Let's fix timed loop with these settings:
           - 1 KHz clock
           - 1 ms period (yes, I know it's short....)
           - offset 0 ms
           - Phase 0
           - Discard missed period (ON) and MAintain original Phase (ON);
           - Timeout: -1.
       If inside this loo, I put a traditional while loop, waiting (say) for an event to occur, and if this event does not arrive, my cFP-2020 hangs! I mean, it becomes unreachable for the debugger, and, more, if I run a ping to it's address, after some cycles it becomes unreachable also from ping!
       Clearly, this code statement lock the fieldPoint, because if I remove the inner while loop all works.
      I know that with 1 ms period, timed loop always finishes late, but I set to discard missed period and timeout to -1. 
       It seems to me that sometimes Timed Loop add heavi overhead to programs, I'm turning to all while loop based tasks, even if my application has to be real-time!
       Advices welcomed! Have a nice day!
    graziano
    Solved!
    Go to Solution.

    I think the issue here is that putting your while loop inside a Timed Loop increases the priority for that task. Timed Loops can have dynamic priorities set over eachother, but they all run between Above Normal and Time Critical priority. My guess is that the debugger and built-in TCP functions run at Above Normal priority or less. This means your cFP isn't hanging, it's doing what it thinks is best. It's trying to finish this task before handling any lower-priority tasks.
    The suggestion to put a Wait function in your loop is an OK one. Keep in mind that you can actually set your wait time to zero instead of one and get the same positive benefit of handling other tasks. I would also suggest that you might look into waiting for this event in a lower priority (non-Timed) loop, and then transmit the appropriate data to your Timed Loop using an RT-FIFO or something. That might give you better handling. Just a thought....
    Jarrod S.
    National Instruments

  • For loop inside  a while loop, what order is that in big o??

    If say I have a for loop inside a while loop, then is that suppose to be in the order of O(n^2) right?? Is there any possibilities to change this into the order of O(n)??

    the other size and the temp size is abstact, which can be defined. This is actually for my union method, my teacher asks me to write this method using the order of O(n) which I think it is not possible. What do you guys think??
    Below is the code I have made:
    public Set<E> union(Set<E> other) {
              int count = 0;
              Iterator<E> iterator1 = other.iterator();
              while (iterator1.hasNext())
                   count++;
              Object[] temp = new Object [data.length+count];
              n = data.length+count;
              for (int i = 0; i<count; i++)
                   temp[i] = data;
              for (int j = count; j<temp.length; j++)
                   temp[j] = iterator1.next();
              data = temp;
              return null;
    but it still has same elements on it and I am thinking of a way on how to remove those same elements

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

  • Error -50103 occured with timed loop inside a while loop

    Hello everyone,
    i wrote an application to sample analog voltage from  DAQ6024E card (see the attachments).
    I have a big while loop in the VI because a I want to add some other functions later.
    In the "WHILE_Cont Acq&Graph Voltage-Int Clk.vi" I use a while loop inside the big while loop to read the samples. It's working properly.
    but when I use a timed loop inside the big while loop (see "TIMED_LOOP_Cont Acq&Graph Voltage-Int Clk.vi"), I get an error -50103 from the timed loop.  It seems that the first cycle is ok, but after the first cycle the error occurs.
    I don't know what happens with the timed loop, anyone can help me? what does the error -50103 mean? thanks a lot!
    PS: I am using LabVIEW 8.0
    Message Edited by molo511 on 10-22-2006 05:21 AM
    Message Edited by molo511 on 10-22-2006 05:23 AM
    Attachments:
    TIMED_LOOP_Cont Acq&Graph Voltage-Int Clk.vi ‏143 KB
    WHILE_Cont Acq&Graph Voltage-Int Clk.vi ‏75 KB

    hi molo511,
    I tested your program but only with simulated devices. I had to delete the wire to the timing, so that the timed while loop runs with 1kHz. Did you already try this? Because this works on my PC.
    I also found a link in our database that might be interesting for you.
    http://digital.ni.com/public.nsf/websearch/04BEDD9E9E91ED3486256D180048116D?OpenDocument
    Greets
    Philipp N.
    NI Application Engineer

  • Fast loop inside a slow loop?

    I have an application reading data once every hour, and writing this reading to disk continously - this works fine, however it looks like LV runs one complete iteration (an hour!) before asking me for the filename to save data in, even though that operation is step 8 of a structure inside the while loop, and the long-time-period timer is at step 9 or 10.
    How do I get the vi to run at normal speed, asking for the filename and writing the first set of data, and THEN going into the long time wait before looping around and executing again. PS - it runs fine, but there is one complete iteration before it comes up asking for the filename. When I run it for xx seconds time period its ok, but not for a long time period.
    Thx! (Newbie here..)

    The problem is that you have made the all too common mistake of using a multiframe sequence. This is why so many experience LabVIEW programmers have abandoned the use of multiframe sequences.
    See, a multiframe sequence is exactly like a single function, or a subVI for that matter. The data from the sequence isn't available until all frames of the sequence have executed. So, you send the data "out" of the sequence, but it "holds" at the output terminal until the sequence has completed, and then is sent "out".
    The other problem is that you have the Write to File... outside of this inner loop, so only after this loop is done (it only iterates once, so I don't even know why you have it there) will the loop exit, and data from that loop b
    e available.
    If I may suggest, try encapsulating each frame of the sequence into a subVI (or something along those lines, such as using multiple single frame sequences in a line). You will need to remove the inner loop, as it is uneccessary.
    It always helps to diagram your code ahead of time. I prefer pseudo code. This is an extremely useful method of aiding in writing your code as it puts things in perspective, in a serial fashion, so that you can visualize what happens, and when, and then just "plop down" each function as they appear in the pseudo code document.
    I hope this helps.

  • Stopping an event structure inside a while loop.

    I am relatively new to LabView, and especially the event structure. I have been looking at previous posts regarding the event structure and people having trouble stopping it. In my VI, I have two event cases in addition to the timeout. I am using this VI for stepper motor control. I have 2 buttons (for each case), one for movement to the left, the other to the right. It runs like it is supposed to, but when I try to stop it I have to press both buttons before it stops. As if the loop has to execute everything inside before stopping.
    In my VI, how can I make the execution stop when I press the stop button? I tried many setups of the stop button and boolean logic (which I believe was correct) but am now stuck.
    Thank you very much ,
    Alek
    Solved!
    Go to Solution.
    Attachments:
    motor control2.vi ‏24 KB

    OK, here's my simplified version. All you need is two event cases.
    Note that (with a tiny difference), the "left" and "right" cases are identical, so they can be handled in one event, reusing most of the shared code.
    We don't need a timeout event
    Just some extra tweaks...
    Message Edited by altenbach on 06-23-2008 05:09 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    RightLeft.png ‏13 KB
    motor_control2MOD.vi ‏15 KB

  • Getting a for loop inside a while loop

    I've been having problems with the code below. I'm trying to get the 'while' loop to work so that the program will continue to run after a user types in a sentence. This is supposed to print out how many times a letter has been typed when a sentence has been put in, but it's not working right. It just keeps adding the first sentences numbers together even when a new sentence is typed out. I don't know what I'm doing wrong with this 'while' loop.
    import java.util.Scanner;
    import java.util.*;
    public class Count
    public static void main (String[] args)
    String phrase; // a string of characters
    int countBlank; // the number of blanks (spaces) in the phrase
    int length; // the length of the phrase
    int countA = 0; // the number of a's in the phrase
    int countT = 0; // the number of t's in the phrase
    int countE = 0;
    int countS = 0;
    char ch; // an individual character in the string
    Scanner scan = new Scanner(System.in);
    // Print a program header
    System.out.println ();
    System.out.println ("Character Counter");
    System.out.println ();
    // Read in a string and find its length
    System.out.println ("Enter a sentence or phrase ('quit' to quit): ");
    phrase = scan.nextLine();
    length = phrase.length();
    // Initialize counts
    countBlank = 0;
    // a while loop to allow user to keep entering phrases
       while (true)
       String line=scan.nextLine();
              System.out.println("Type quit to quit or enter a new phrase.");
         if(line.equals("quit"))
    break;
    // a for loop to go through the string character by character
    // and count the blank spaces
    for(int i = 0; i < phrase.length(); i++)
    ch = phrase.charAt(i);
    switch (ch)
    case ' ': countBlank++;
    break;
    case 'a':
    case 'A': countA++;
    break;
    case 't':
    case 'T': countT++;
    break;
    case 'e':
    case 'E': countE++;
    break;
    case 's':
    case 'S': countS++;
    break;
    // Print the results
    System.out.println ();
    System.out.println ("Number of blank spaces: " + countBlank);
    System.out.println ("Number of A's: " + countA);
    System.out.println ("Number of T's: " + countT);
    System.out.println ("Number of E's: " + countE);
    System.out.println ("Number of S's: " + countS);
    System.out.println ();
    }

    Ok well I don't really understand what you're saying, but here's an improved version of my code and I can get it to work, but I don't know how to turn the "do while" loop into just a "while" loop.
    import java.util.Scanner;
    public class Count3
         public static void main (String[] args) {
              String      phrase;           // a string of characters
              int      countBlank=0;      // the number of blanks (spaces) in the phrase
              int      length;           // the length of the phrase
              char      ch;                // an individual character in the string
              int      countA=0;       
              int      countE=0;
              int      countS=0;
              int      countT=0;
              String quit = new String("quit"); //String wasn't initialized
              Scanner scan = new Scanner(System.in);
              // Print a program header
              System.out.println ();
              System.out.println ("Character Counter");
              System.out.println ();
              do { //do-while loop
              // Read in a string and find its length
              System.out.println("Enter a sentence or phrase, or type \"quit\" to quit: ");
              phrase = scan.nextLine();
              length = phrase.length();
              // a for loop to go through the string character by character
              // and count the blank spaces, a's, e's, s', and t's
                   for (int i = 0; i <= length-1; i++) {
                        ch = phrase.charAt(i);
                        switch (ch) {
                             case ' ': countBlank++;
                             break;
                             case 'a':
                             case 'A': countA++;
                             break;
                             case 'e':
                             case 'E': countE++;
                             break;
                             case 's':
                             case 'S': countS++;
                             break;
                             case 't':
                             case 'T': countT++;
                             break;
                   // Print the results
                   System.out.println ();
                   System.out.println ("Number of blank spaces: " + countBlank);
                   System.out.println ("Number of a's: " + countA);
                   System.out.println ("Number of e's: " + countE);
                   System.out.println ("Number of s's: " + countS);
                   System.out.println ("Number of t's: " + countT);
                   System.out.println ();
                   countA=0; countE=0; countS=0; countT=0; countBlank=0;
              }while (!(phrase.equalsIgnoreCase(quit)));          
         }//end main
    }//end class Count

  • For Loop Inside A For Loop

    Is it possible to execute all the iterations of the inside for loop for each iteration of the outside for loop? I have attached a screenshot of my program if it helps. If it is possible could you tell me how to do it plz?
    Solved!
    Go to Solution.
    Attachments:
    Capture.PNG ‏53 KB

    One thought I have is that I think you want those feedback nodes reinitializing for each iteration of the outter loop.  Personally, I would change them to be shift registers (it would clean up your diagram a little bit).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Event controll: How to stop a running while loop inside a event structure

    Hello,
    I have some problems with controlling a while loop inside a event structure (see attached VI).
    I habe 3 buttons ("Start Measurement, Stop Measurement, Quit Program"). When a measurement is running, it should be possible to stop the measurement by clicking on "Stop Measurement", but this does not work.
    Has anyone an idea?
    Thanks a lot and best regards,
    Michael
    Message Edited by MichaGue_01 on 04-23-2010 04:37 AM
    Solved!
    Go to Solution.
    Attachments:
    Event_Controll.vi ‏27 KB

    Hello,
    Try not to use while loops inside a Event structure.
    My approach is using two While loops (one will have only the Event structure).
    I had to use to Flag buttons that make it a bit more complicated but i am sure somebody will come up with a better idea, or you might want to have a think about it yourself.
    Have a look on the modified version on the attachment.
    Once you are happy how it works then you can Hide the 2 flag buttons from the Front Pannel by going to Block diagram right-click the indicators and choose option "Hide Indicators/Controls"
    I did it in LV 8.6 so i hope you can open it on your PC if not i can downgrade it.
    If you have any problem let us know.
    Regards
    Dimitrios
    Test Systems Computing Engineer
    Cummins Turbo-Technologies
    Attachments:
    Event_Controll[1]_modified.vi ‏18 KB

  • How can I vary a PWM´s duty cycle inside a while loop?

    Hi,
    I'm using the "Generate Pulse Train.vi" to generate pwm signals in counters 0 and 1 in order to drive a DC motor both ways.
    The problem is, I need to control the movement of the dc motor with my PI controller which is inside a while loop. I've tried letting the "generate pulse train.vi" outside the while loop, but the problem is, it only changes the value of the duty cycle when the loop is stopped. I also tried putting it inside the loop, but then it doesn't even work.
    So, how can I vary a PWM´s duty cycle inside a while loop?
    I'm attaching the VI with the PI controller.
    Thanks for your help!
    Guilherme
    Attachments:
    controleValvula.vi ‏332 KB

    Here's some code I threw together a while back to change a duty cycle on the fly. It generates a fixed 5KHz or 25KHz frequency depending on laser selection, then allows duty cycle to be changed continously. Maybe you can use the premise of it for your application.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    "It’s the questions that drive us.”
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    Attachments:
    Pulse_Width_Modulator.llb ‏197 KB

  • How to pass a value from inside a while loop outside the loop

    Hello to everybody, I have been searching through the forum but I have not found a certain answer for my problem. I would try to explain my problem as breefly as posible:
    I have to send by a BNC2120 two signals and acquire an other one thats comes from a preassure sensor. That part is done by introducing simulating and acquiring DAQmx inside while loops.It is sycronized by my self, proving such diferent values (is not the optimum, but is only the first prototype) and works as I expected. Well, then I want to sample some of the values of these signals, that is done with relays and local variables to get the value in the instant I want to sample. Here begin my problems: I want to extract the sample values out of the while loops without restarting them, I mean: I do not want to stop the while loops because the acquisition and the generation of the signal must be continuous, but I do not know if it is posible to put the while loops in "standby" until I operate with the values I have sampled and then the signal generator and the acquiere continues from when it has stoped before. Particulary I want to obtain the value of the top while loop (inside a case) when the counter arrives at 15.
    I have proved to do with local variables, global variables, making a state machine, with event cases, with flat secuences...I have been reading about and proving diferent posible solutions for this week and the whole past week and I have not found the solution.
    If any of you know how I can do this thing, I would be loved to listen your opinions. My proyect is above: 
    Thank you a lot in advance.
    Sinceresly,
    Miguel.
    Attachments:
    maq_estados_event_case.vi ‏239 KB

    It definately sounds like what you really want is a Producer/Consumer.  It is an architecture that uses Queues to pass data from a data generation loop (producter, your DAQ loop) and a data processor (consumer).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How do I break a for loop (inside) and a while loop (outside) at the same time by a control button

    I have a while loop (outside) and a for loop (inside) and a control button within the for loop.  I want to stop the program by click the botton without finishing the for loop.  How can I do that?
    Thank you in advance.

    HI Please find attached snapshot Regards, Santosh
    Message Edited by SanRac on 12-17-2009 05:12 AM
    Message Edited by SanRac on 12-17-2009 05:13 AM
    Attachments:
    Snap1.png ‏4 KB

  • Exit a while loop inside an event case

    Hi All, I have a multi-page program. One of it is used to read some analog signal via a USB block continuously.
    What I want is when clicking this page, this while loop is activated. Then we can monitor the data. When we click other pages or "Stop" button, this while loop will be terminated. And we can use the other pages to do something else.
    Right now I got difficuties in stop the while loop. I do not want to stop the running of the whole program, just want to jump out of this while loop then do other operation.
    Could anyone give me some advise how to do it? Thank you very much! 

    Hi RavensFan, thank you for your reply.Actually this is not my real code  because the original one is very very compliacted.
    In real code, the tab control you see in inside the bigger while loop, that loop makes the whole program work.
    And as what I pointed, the purpose is when I click this tab (if we do not want it to trigger, we can place another "START" button to trigger), an internal while loop inside begins to run. This while loop keeps showing the real time analog signal.
    And if I do not want to use this "real time monitoring" function, I want to click somewhere (or doing anything else that can work) to jump out of this internal while loop and keep on using some other functions of the program.
    Could you advise about that? Thank you very much! 

Maybe you are looking for

  • Really slow disk access

    our iMac runs like a dog. I've max'd RAM, cleaned and optimized the hard drive. Configured with two non-admin users (myself & my wife - I need right-click but it drives here crazy), and an admin account. iTunes and iPhoto libraries are shared, and th

  • Check path type

    Hello everyone. I have a scenario where i have a field in the program which contains the file path(directory) name. I need to find out whether this file path name is on application server or PC. Is there any FM for this...............or any solution

  • Disable first Column in jTable

    Hello people my problem is I use jTable and in the table I need to disable first column so that the user is not able to change edit the values that are listed in this column. Please help me with some code samples if possible. Thanks in advance.

  • Why am I unable to convert my PDFs into Word Documents anymore?  I've had no problem until now and been signed up forever.  Please inform what the problem is???  TU!

    Please inform me why I am unable to convert my PDFs to Word Documents anymore.  I've been signed up and paid forever now and no problems until today,  Please inform me of what the problem is?  Thanks bunches!  :- @(

  • How to create a tcode for table maitenance

    i have a ztable which is having a maintenace view now  i have to create a transaction code for the given table maintenance please can anyone give me the details how to create it and what steps i have to follow.