To use or not to use: while loop?

Being relatively new to LabVIEW and excited by the event programming Structure makes me think that a While loop should almost never be used.

A While loop uses "polling" to see if a condition is fulfilled or not before you stop the execution, which eats memory. (No pun intended) while event Structures

don't constantly gobble up CPU memory and waiting for something to happen, and then runs.

Can someone give me a simple and good example of when it is appropriate to use a While loop? Do not hesitate to talk about certain situations more complicated, requiring a While loop

which cannot really be addressed with the programming of the Structure of the event.

While loops and structures of the event go hand in hand. You almost always want to place the structure of the event within a while loop. If you do not you will serve a single event. The while loop will allow you to repair all the events. It is important to note that when there is no event loop will not be doing anything. He will be inactive and essentially no time consume CPU. The structure of the event will have to wait for the next event.

Tags: NI Software

Similar Questions

  • Using 'while' loop or something like that

    Gurus,

    To do a selection online to compare a literal number. I thought I could use a "while loop" for this but get errors. Any other suggestions out there?


    while (select count(1) from mtl_cycle_count_entries where cycle_count_header_id = crec_purge_cc_by_hdr.cycle_count_header_id) > 0
      loop
         ...
    end loop;
    Thank you.

    Points for correct or helpful answers.

    PL/SQL is two other languages. PL and SQL - integrated at the level of the source code. It is not T - SQL where the SQL language have been extended with additional procedures and conditional structures and treatment orders.

    If you can not run a SQL and compare that with a PL variable by using a condition WHILE . The next type of conditional processing is necessary.

    loop
       select
          count(1) into someVar
       from mtl_cycle_count_entries where cycle_count_header_id = crec_purge_cc_by_hdr.cycle_count_header_id;
    
        exit when someVar <= 0;
    
       .. code ..
    
    end loop;
    

    Select ugly even if - as the part must be modular in function.

    So put this selection in a function, will allow you to do what follows - as you expected:

    while someFunction > 0 loop
      .. code ..
    end loop;
    

    Points for correct or helpful answers.

    Oh please... do you honestly think that I spend my free time here, for points? The points are useless and meaningless. It can't buy you a beer. He does not buy respect you. It would be silly to put on a RESUME.

    It is therefore a bit insulting to have points restless as a carrot to meet a problem here. Some of us don't never ask for to the points system. Some of us do not think it helps anyway to the OTN forums - except to raise the noise level from those who think that forum points makes gurus and experts...

    Sorry for this rant - but the points thing is IMO the worst feature that has been added to the RTO since I've been around.

  • Need help to use while LOOP to run immediately

    Hello

    I use the Oracle 11 g R2 database.

    I need to use 'while' below statement so that I'm going to immediate execution with the following ranges in a LOOP.

    USING 100, 200
    USING 201, 300
    WITH THE HELP OF 301, 400
    USING 401, 500
    declare
    v_maxseq_id number:=100;
    v_minseq_id number:= 500;
    
    begin
    --WHILE LOOP
    
    EXECUTE IMMEDIATE 'insert /*+APPEND*/all into stage_parsed_while
    select * from STAGE_PARSED_h2 WHERE src_file = ''a'' AND load_date = ''03-apr-2013''
    and seq_id between :1 and :2'
    USING v_minseq_id , v_maxseq_id ;
    
    
    end;
    Kindly help... Thank you

    Your syntax for the While loop:

    set serveroutput on;
    declare
      i pls_integer := 101;
    begin
      while i < 500 loop
        dbms_output.put_line('Min :: ' ||i || '; Max :: ' || to_char(i + 99));
        i := i + 100;
      end loop;
    end;
    
    anonymous block completed
    Min :: 101; Max :: 200
    Min :: 201; Max :: 300
    Min :: 301; Max :: 400
    Min :: 401; Max :: 500
    

    And Yes, I'm agree with suggestion of knapen to accomplish the task with a single static SQL, rather than go for dynamic SQL (which is the first wrong approach) and then using loops to slow further (which would be another mistake).

  • do not shutdown of while loop

    Hello

    I'm LabVIEW and motion controller software OR hardware PCI-7332/UMI-7774 and control a stepper motor.

    My question is:

    When flipping enc = 5 whereas the loop stops

    but with the rest of the value of 20 to 500.

    Why isn't rest zero.

    When the indicator test installation is checked

    the while loop does not stop.

    Please see the attached code.

    Thank you

    The rest would have to do with what happens inside the Subvi, which was not included. The output value of is not stop to an exact multiple of 4095. The question is why that is the case.

    Mike...

  • How to create a control of time for the while loop?

    Hi all

    I want to control my time running of the loop. In other words, I want to stop everything in the execution of the loop after a time (in ms) that is defined by the user. For example user defines Control Panel for 5 seconds before a while loop runs and stops after 5 seconds.

    I don't know is it possible with the while loop. I managed with the timed loop, but this must be wrong with my application. Y at - it of the other loops for timed control if it is not possible with while loop? There is also a simple loop with .vi random number (0-1) as an attachment.

    Best regards

    Jick

    Hi again,

    I managed to solve my problem right after I posted my first message. I did it with the passage of time and the register shift (for the elapsed time of reset).

    Thanks for your replies anyway!

    Best R

    Jick

  • How to 'continue' a 'while' loop using an "if"?

    I have a loop 'while' continuous operation, by taking a step at each iteration. In each such iteration I save this measure unique to the file AND display it on a chart. From time to time, I have "out-of-range" measures, which are displayed as 1E-37 or 1E + 37 on the graph and poured on the record, and are not relevant (for me, it is). With the help of a simple interpreter, like python, I could use an 'if' statement to check if the reading is indeed irrelevant and if so, 'continue' in the loop 'while' so that it stops the current iteration and starts a new.

    How we not implements such a thing in LabVIEW?

    Thank you

    Amit

    Hi Amit,

    There was no 'cynicism', not at all! You ask a few notions of LabVIEW base so I suggested where to find that...

    "but this would require having wrap all code inside the"while"loop."

    OK, then you should explain the difference of a IF/THEN construct textual languages. Made a simple

    IF test

    {do something here}

    ON THE OTHER

    {do something here}

    not wrap the code inside a structure?

    A CASE structure does exactly the same thing and I don't see anything more simple as followed by comparison of two cases. What is complicated in a case around another structure design code?

  • How to use count imaq objects in a while loop?

    Hello, I am using objects IMAQ County and works well, but when I use a loop and I want to change the picture that I analyze to see results instantly, the search box, and the locations of the remains of the objects in the picture, even if I return to the original (for example at the threshold) values, objects of the location and the green rectangle remains there as the next image :

    This is the pattern I use:

    I used this same setup with the 3D IMAQ view and it works well, I change the values and changes in 3D view so do I.

    I use unduly the IMAQ dispose?

    Thank you very much for your help and comments.

    Bene

    The problem is due to the way works IMAQ Vision: the thread of the image contains a reference (handle), to the image, not the image itself. Means that once an image has been changed somewhere, the mods are propagated worldwide.

    The solution is simple: just add an IMAQ clear Overlay immediately upon entering the while loop (and add a small timer inside the loop).

    As an example, see the vi attached.

  • Use of LabView delay in a while loop instead of use the inherent instrument of time loop.

    I have a lmg500 sez I use. It has the possibility of continuous measurement of data, with a cycle of user control loop (always using a while loop but the delay comes from the instrument). The problem is that the time of the loop is not constant. Can I use a very short time (100ms) as the cycle of the instrument of the time, but use a longer period in time loop collect data?

    I know that many instrument offers the same capabilities, so the issue is relevant to each of them.

    Thanks for any help

    You're not going to be accurate with Windows. The time between samples should be that you have programmed the instrument (i.e. the time between each value in the table 1 d) but the rate of the iteration of a while loop always will be the subject of a jig on a bone not real-time.

  • Using asynchronous calls in a while loop. How 'Skip' node and only retrieve data as it is treated

    Maybe I'm not understand asynchronous calls... but I thought I should be able to call one another VI and essentially 'jump' it is the node and only receive data as the called VI treats.  In other words, similar to the Run of VI, I can wire a wait until done? with a fake and the main VI will not wait for the other VI end of race.  The main VI continues to function, and when it passes the called node of the VI, it will receive data if it happens to be there.

    How can I call a VI in a while loop and do not wait so he could spit out the results?  Data flow is my enemy on this one...

    The first VI treats its own figures (using the iteration count) and displays them on the PC.  Other indicators are the data of the called VI.  I want to be able to work around the blue circle node and receive data only that it will be available.

    Any help is appreciated.  Thank you.

    What I said OR the 'Start asynchronous call' is the preferred method for starting background tasks. This call is usually used to run background tasks. For example, you have a process of journal. When your application starts it would use the "asynchronous call Start" to start the process of journal and then move on to the other stuf. The process of the journal would then happily run in the background and the main application is free to do other things. Of course when implementing these types of systems you need a way to coordinate things like exit. This is where the queues and stuff come it.

  • Problems to use TimerEvent in While loop

    Hello

    I try to use a while loop a TimerEvent. In the example below, I created the function init should loop through values myArray, tracing of each value to every three seconds. It seems, however, that because I am incrementing the value currentNum outside the while loop (from the timerHandler function), the just loop continues to turn until the Flash no longer responds.

    var myArray:Array = new Array ("one", "two", "three", "four", "five");

    var currentNum:int;

    myTimer var = new Timer (3000, 1);

    function init (): void {}

    while (currentNum < myArray.length) {}

    trace (myArray [currentNum]);

    myTimer.addEventListener (TimerEvent.TIMER_COMPLETE, timerHandler);

    myTimer.start ();

    }

    }

    function timerHandler(e:TimerEvent):void {}

    currentNum += 1;

    }

    init();

    I wonder if what I try to do is just simply not possible or if I'm missing something.

    Thanks in advance for any thoughts on the issue.

    This loop will run at the speed of light of the processor.  Put the timer inside it will not slow down it.  Chances are that you do not want to use a loop of any kind other than that which is developed through the use of the timer and the single event handler function.  Maybe together the repeat of the timer value be based on the length of the array.

  • How to increase code efficiency in a while loop (using PXI5105 for sampling outside signal digitalizer)

    Theoretically, we want the PXI-5105 (digitizer) have 302 record with each record has a 1260 sample (the save operation is inside a while loop) in approximately 30ms, however we have found that for each period (30ms), the PXI5105 only perform about 10 records. It is so wired. I wonder if the operations inside the while loop consume more time (for example 3MS), so that he cannot have 302 records even the PXI-5105 have 60 M/s speed of sampling. Is it true, you can find my labview code and if possible can you give me some suggestion in the most short time of operation of the loop.

    Please find attached labview code.

    Hi g_l_g_s,

    The digitizer PXI-5105 acquires data at the speed that you specify and stores the data in its memory embedded (up to 512 MB). The data is then sent to your computer when the Multi Fetch Cluster.vi is called. In VI that you posted, you are only fetch record during each while the loop iteration. If you want to retrieve 302 records you will need to specify 302 files in the horizontal Timing.vi to configure. For more information about scanners, you might find the DevZone, hereuseful.

    To determine the amount of time it takes for each while the loop iteration, you can consider using the structure of code in the example comparison community calendar, which is located here.

  • Judgment of multiple while loop running at different rates to stop using the single Boolean stop button

    Hello

    I'm on the block diagram of 4 loops, do different tasks. They are independent of each other, but need to see the unique front panel - some of the wonders of labview!

    Now, I want to have a unique stop button which will in fact be a back button to return to the main screen by stopping all four loops on the block diagram. I used the stop button (switch released) with local variable to stop the three other loops. He stops the vi but it is not a good stop vi to stop properly and the grid on the performance of the front panel. Now all loops run also at different rates, so it is not necessary that all loops are stopped immediately when one of the loop is stopped. Can't really think of a better way. All the ideas!

    Kind regards

    Austin

    Variables local is ok in this case, but you will need to keep the control in switching mode (no lock).

    A better solution would be to have all the loops as a structure of event all listening value stop change. Or have the Stop value change event generate a user defined output event or similar.

    /Y

  • Why used this simple while loop work?

    The main idea is to create a search feature on a form. I want to move to the next record, until I find what I'm looking for. Here is the code:

    These variables to get the numeric values of the NumericField5 and NumericField8. RawValue of NumericField5 will be below the NumericField8.

    strt var = NumericField5.rawValue;

    var end = NumericField8.rawValue;

    While variable rawValue strt is smaller that the variable end rawValue, move to the next record in the DataConnection.

    While (strt < end)

    {

    xfa.sourceSet.DataConnection.next ();

    STRT = NumericField5.rawValue;

    }

    When it works, evil created another loop of research when the variables range from end to beginning.
    I don't know why, acrobat crashes each time. Help, please!

    You can store the contents of the field before you enter the loop, then use a loop for wait until he changed. Then you would update the content stored with the new value so that the next time through await you on the right thing.

    Paul

  • The use of registers at offset in a while loop that never loop

    Here's a picture of 'syslog_Device function Engine.vi. This isn't really a question specifically about this vi, but rather a technique I see here.

    First thing I noticed, it was a while loop always outputs, never loops. And shift registers. This serves for the VI can retain values between calls, almost like what I consider a local variable which are persistent between function calls in another language? It is an interesting way to accomplish what I have not looked at.

    Please tell me if I'm missing what is happening here.

    It is a driving force.

    It's a code construct that allows you to encapsulate data and features that are available in multiple threads.

    The nugget I linked above explains their operation the theory behind them and follow-up discussions in discussion on how to exploit them.

    Good questin incidentally!

    Ben

  • Subvi with while loop + event structure works is not in multi tab VI

    Hi all

    I'm developing an interface for the control of a prober using Labview 2012, and I'm stuck with a question.

    First I provide you with a simplified version of my VI control interface and the sub - VI used to generate and manage the mappings of wafer.

    The VI is composed of several tabs: Prober initialization, manipulation of Wafer, Wafer map, status, error.

    The sub - VI can:

    1 / initialize the grid to display the map (Subvi Init grid not provided here)

    2 / coordinates XY for import a txt file (Subvi Wafer map Import)

    3 / view contact information and the index of the sector under the cursor

    4 / and what position die is double clicked and the Boolean 'Edit Wafer map' is true, then the user can change the State (color) of the matrix between die on platelets and selected Die

    My question:

    If I use the sub - VI by itself, it works fine. However, when I use it as a Subvi in the 'Wafer map' tab, the plan does not rise and I can use any features incorporated into the Subvi.

    I suspect that the while loop + structure of the event of sub - VI the bottleneck here.

    However I do not know which way to go, that's why I'd be happy to have some advice and help here.

    Thank you.

    Florian

    The question arises because your hand loop 'for' cycles of 33 times.  In the loop of 32, appears your Subvi and execution is passed to your Subvi.  During this time your main VI expected Subvi in the end, she never does.  You could spend your Subvi out of the main loop of the program and run in a separate process, in order to pass data using queues, but you have to find a way to close the Subvi (i.e. a queue).  By moving the Subvi on the main process, it is independent and you can do what you want to do with the events and others.

Maybe you are looking for