Stacked sequence inside for loop question

Hi everyone,
I am new to LabVIEW and I just want to make a for loop with a stack sequence inside. I want it so that when the for loop executes for the n-th time, the stacked sequence is at the n-th frame (because each frame contains different tasks to be carried out). Is this possible? or is there an alternative equivalent method? Please help me out! Thanks!!

Thank you Norbert for the words of advice.
Try to avoid Stacked Sequence Structures at all cost.  They are a nightmare to deal with when maintaining the code and they do not offer simple scalability, especially if you need to deal with parallelism.
As Norbert suggested, State Machines is the way to go.  Try to avoid naming covention such as 1...2...3...4...5.......9999.  Give the name of each case based on what that case does.  Create a TypeDef Control for the state selector (you'll thank me after having changed it for the 5th time   ).
There are probably 100's of examples in this forum.
RayR

Similar Messages

  • How do we use if statement in labview?moreover can i use if statement inside for loop?

    how do we use if statement in labview?moreover can i use if statement inside for loop?

    The if statement in LabVIEW is the Case structure. You can find that on the Structures palette right next to the For Loop. If you're still on the same subject about terminating a for loop early, then what you do is enclose your functions inside the loop with a case statment and make one of the case's empty except for one or more constants that you might have to wire. Hopefully, the attached picture will explain what I mean. Also, as I mentioned in one of your other posts, I think this technique is not as good as using a while loop. The array in the attached example is the same size no matter what and you may have to handle stripping extra or invalid elements.
    Attachments:
    For_Loop_with_Case.jpg ‏21 KB

  • Best practice: Using break statement inside for loop

    Hi All,
    Using break statment inside FOR loop is a best practice or not?
    I have given some sample code:
    1. With break statement
    2. With some boolean variable that decide whether to come out of the loop or not.
    for(int i = 0; i < 10; i++){
    if(i == 5){
    break;
    boolean breakForLoop = false;
    for(int i = 0; i < 10 && !breakForLoop; i++){
    if(i == 5){
    breakForLoop = true;
    The example may be a stupid one. But i want to know which one is good?
    Thanks and Regards,
    Ashok kumar B.

    Actually, it's bad practice to use break anywhere other than in conjunction with a switch statement.Presumably, if you favour:
    boolean test = true;
    while (test)
      test = foo && bar;
      if (test)
    }overfor (;;)
      if (! ( foo && bar) ) break;
    }then you also favour
    boolean test = foo && bar;
    if (test)
    }overif (foo && bar)
    }Or can you justify your statement with any example which doesn't cause more complexity, more variables in scope, and multiple assignments and tests?

  • State Diagram inside For Loop

    I created a fairly involved for-loop with a flat sequence inside of it.  The sequence had about four events that occured, and since it was kind of ugly, I thought I'd try the State Diagram Toolkit to replace the majority of the code.  When I selected state diagram from the pallete, I was outside my for-loop.  I drew up the various states/transitions, then realized that all this code needed to be inside the for-loop, but LV won't let me place state diagram-generated code inside the for-loop.  I select everything related to the state diagram, but when I drag into the for-loop, only the comments come inside.  I even tried generating a new for-loop and placing the state code inside.  No luck. Any thoughts?

    "Any thoughts?"
    Yes but not any that will help.
    1) Just modify your SD so that the exit loops back to the start while there are still things to do. Forget the outer For loop.
    2) THe observations you reported are correct. When I first discovered these limitiations I said "That sucks!". Since then I have learned a bit and have grown to love the SDE.
    The SDE is JUST (note: "just" is a four letter word around here ) a LV application that ofers a very limited GUI consisting of a picture control that then scripts (see LAVA Scripting Forum for info on scripting) your SD for you. SCripting LV code is no easy task. My experiments with scripting has shown that I have to keep a database of the contents of the LV diagram my code is developing to keep track of what is where. Well it turns out that the structure of a LV diagram is a lot like the structure of a FP in that you start with a "root" object either the FP or the BD. THe BD then has structures on it, like seq's loops etc with unlited nesting possible.
    Now the SD created by the SDE is really just a fancy while loop with an case structure and code to support the driving enum. In order for you to be able to edit the SD the SDE needs to know what is htere already so it can show the diagram. It "KNOWS" by looking at its internal DB (I believe is stored inside of VI along with the enum.ctl) of the SD. To keep the DB updated, the SDE must be used to manipulate the SD.
    Stop rambling and guessing and get to the point!
    Moving the SD is just not supported by the SDE so it can not be done. To do so would require the SDE be able to "look" at the diagram, and repeat all of its work in the new location in the diagram.
    BTW: Thank you for trying out and asking about the SDE. the more talking we do on this subject, the sooner the SDE will be updated.
    My SDE wishlist (partial)
    Add comments to diagram from SDE screen.
    Add data structures to SD (shift registers) from SDE screen.
    Add "un-do".
    Select multiple objects on SDE screen and move or allign.
    Select multiple objects on SDE screen and do "create sub-State-Diagram".
    Allow watching more than one SDE in execution highlighting at the same time.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Cursor For loop question

    Hi,
    I have a cursor in my plsql and I am trying to get the record through a FOR loop. I know that for loop will take care of opening, fetching and closing the cursor implicitly.
    Ex.
    declare
    cursor c1 is
    select * from emp;
    begin
    for l_rec in c1 loop
    end loop;
    My question is i want to check whether the cursor in the for loop is returning any record or not using IF condition.
    where and how i will find that?
    Can anyone help how to do that.
    Rds,
    Nag

    without using boolean variables.Obvious question, WHY?
    If you are so particular..
    SQL> declare
      2   cursor c1 is
      3        select empno, ename, job
      4        from emp
      5        where empno = 7839123;
      6   ex exception;
      7   rec c1%rowtype;
      8  begin
      9   open c1;
    10   fetch c1 into rec;
    11   if c1%notfound then
    12    raise ex;
    13   end if;
    14   loop
    15    dbms_output.put_line(rec.empno||'-->'||rec.ename||'-->'||rec.job);
    16    fetch c1 into rec;
    17    exit when c1%notfound;
    18   end loop;
    19  exception
    20   when ex then
    21    dbms_output.put_line('cur not found');
    22  end;
    23  /
    cur not found
    PL/SQL procedure successfully completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • VERY IMPORTANT FOR LOOP QUESTION

    public class ForTest2 {
         public static void main(String args[]) {
              int i=0, j = 0;
              for (j=0; j < 10; j++) {
                   i++;
                   System.out.println("i is: " + i);
                   System.out.println("j is: " + j);
              System.out.println("Final i is: " + i);
              System.out.println("Final j is: " + j);
    }j ends up being 10. Why? It should only be 9. This is as when j is 10 the for loop fails, so j++ shouldnt happen.

    First, please, please, please stop using all caps. It's extremely annoying.
    Second, don't mark your question as urgent or important. It is 100
    % guaranteed NOT to get you help any faster, and it might just delay you getting help because it's annoying.
    As for your question, you're misunderstanding how the for loop works. j HAS to become 10 for it to end. The loop body executes as long as j < 10. If j didn't become 10, the loop body couldn't terminate, because j<10 would always be true.
    The body is executed, the j++ is executed, then the j<10 is tested.
    int j;
    for (j = 0; j < 10; j++) {
        // body
    // is equivalent to
    int j;
    j = 0;
    while (j < 10) {
        // body
        j++:
    }

  • Is it possible to put property node inside for loop?

    I have created three separate property nodes (plot color) for my 3 XY graphs.
    Is it possible to have one property node, say plot_color_i and put this inside the for loop where i runs from 1 to N,
    where plot_color_1 would update XY Graph 1, plot_color_2 would update XY Graph 2, etc.?
    See the attached VI.
    Solved!
    Go to Solution.
    Attachments:
    XY Plot Example.vi ‏18 KB

    Yes.  Create an array of references of the XY graphs and have that auto-index into the property node in the For Loop
    Attachments:
    XYPlotExampleMOD.vi ‏18 KB

  • Initializing variables inside for-loop?

    Dear all,
    It's been a while since I last programmed in Java, and my skills seem to be a bit rusty.
    I have a question for you here: suppose I need to initialize n (let's say 10) different integers, I suppose I couldn't use something like this:
    for(int i = 0; i < 10; i++){
      int <&iquest;VALUE?> = i;
    }Is there a way to dynamically initialize <VALUE>, for instance something like ("integer" + i)? (integer0=0, integer1=1, integer2=2, etc.)
    Thank you,
    Maarten

    You need to declare the arrays in a context outside of the for loop, the for loop context will end and so will all of your locally declared variables. Now there is a way around that:
    Make an ArrayList, in a "Global context" to your loop, and initialize your variables in the for loop, then add them to the ArrayList, once you are out of the loop, then the ArrayList will hold your references to your variables and keep them from being disposed. When you are done with them, then just remove them from the ArrayList.
    ArrayList<myNodes> al = new ArrayList<myNodes>(); //in a "global context"
    for(int i=0; i<iSomeNumber; i++){
      MyNode n = new myNode();
      //do what ever
      al.add(n);
    }If you need key values to look up your nodes by, then you a Map of some type instead of an ArrayList.

  • A simple for loop question

    Hi
    Lets say I have an array with boolean values in it:
    my_array = [ false , false , false ]
    My question is:
    How do you make a function to check, if the value is all
    false, than do this (not only one but all false than trigger a
    function)
    thank you

    The 350Z,
    > Lets say I have an array with boolean values in it:
    > my_array = [ false , false , false ]
    I'm with ya.
    > My question is:
    > How do you make a function to check, if the value is
    > all false, than do this (not only one but all false than
    > trigger a function)
    Your subject line already states the answer. A for loop
    would come in
    handy. :) In your case, you're looking for all three values
    to be false.
    If even a mere one of them is true, the whole result doesn't
    count. Let's
    write a function that returns true if all three are false,
    and returns false
    if any are true.
    function checkWholeArray(arr:Array):Boolean {
    for (var n:Number = 0; n < arr.length; n++) {
    if (arr[n] == true) {
    return false;
    return true;
    To use this function, you could call it and supply your
    array as the
    parameter ...
    checkWholeArray(my_array);
    ... and since that resolves to either true or false, you
    could even use that
    expression in an if statement.
    if (checkWholeArray(my_array)) {
    // do something
    } else {
    // do something else
    The for loop simply steps through each element in the
    passed-in array.
    If the current element is true, then the desired outcome --
    that all
    elements are false -- is a loss, so the function returns
    false and
    immediately stops (the return statement always exits the
    function at that
    point). Otherwise, the for loop finishes, and the function
    returns true.
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Commit inside For Loop

    Hi,
    I have a query which is updating millions of records and is inside a for loop . I have issued commit inside that for loop only . Which one will be better . Should I issue the commit inside the for loop or outside it .
    Thanks in Advance,
    Rahul Guha Ray

    No it is not technically true but ajallen has a valid point. Under traditional rollback segment management reading and updating the same table where large quantities of data were changed with frequent committing was probably the number one cause of snapshot too old errors. However, there are many factors that play into this so even under traditional rollback segment management how likely you are to get an error depends: total size of transaction, total run time, concurrent access, and amount on rollback space available.
    With undo segment space management it largely depends on the total transaction size and runtime verse how much undo you have and your retention policy.
    At some point re-opening the query may indeed be a good idea. One approach is to code to re-open the query only on getting the 1555 error. Some updates however cannot be resumed easily as the update does not mark the row in such a way as the query or where clause conditions can exclude it. In cases like this saving restart information with each commit is necessary.
    A lot of different factors have to go into the decision of how often to commit.
    -- Mark D Powell --

  • Insert Procedure For LOOP question

    Hi all,
    I have made a Procedure which basically massages data and loads into into another table and makes a time record aswell. I am practising my good datawarehousing practise (So load table into real DW_table)
    I am using an Explicit Cursor For Loop....
    What i was wondering is if there is some type of SQL%rowcount I can do in order to check that the record where "INSERTED" into dw_client and dw_time; before i create a auit record in another table. I know this is normally done using triggers, but I am testing this for a Datawarehouse and not sure triggers are the best answer. But please correct me if im wrong:
    I basically wanted to put another insert in there, if the inserts actually ran!

    RPuttagunta wrote:
    Why can you not use a merge statement in your code instead of writing a whole procedure for it?
    merge into mehmet_schema.dw_client a
    using
    mehmet_schema.client.....
    If I understand it right, you are checking if there are any records that exists in 'client' and doesn't exist in 'dw_client' table, then, you are inserting. Is that correct?Yes that is correct. Also I am inserting into the dw_time table using the sqeuence values, so i didnt think merge statement would do this!
    aslo i wanted to use this procedure to clean up some of the data, as you can see in my Cursor, again why i havent used a merge
    Edited by: oraCraft on 09-Nov-2010 09:53

  • For loop question

    Hi here is a segment of my code:
    public void vietaLoop(){
         int loopParameter;
         final int START_CONDITION=0;
         final long END_CONDITION=no_Terms;
         double initialTerm = Math.sqrt(2)/2;
         double newTerm;
         double previousTerm;
         /* calculate the next PI term */
         newTerm = Math.sqrt(2+previousTerm);
         /* assign new term to previous */
         previousTerm = newTerm;
         for (loopParameter = START_CONDITION; loopParameter < END_CONDITION;
         loopParameter++)
         /* Prints the new PI approximation */
         System.out.println(+ newTerm);
    im having loads of trouble, above is how far I have got but I'm unable to 'call' the previous calculation to be included in the next calculation to calculate the new term of PI. as a result all my output is the same..... ie = 1.645.......
    If anyone could point me in the right direct... its really getting to me. Thanks.

    Hi there,
    Is this what you want?
    import java.awt.*;
    class vietaLoop
        public static void main(String[] args)
              int loopParameter;
              int no_Terms=10;
              int START_CONDITION=0;
              int END_CONDITION=no_Terms;
              double initialTerm=Math.sqrt(2)/2;
              double newTerm;
              double previousTerm;
              previousTerm=initialTerm;
              for (loopParameter=0; loopParameter<END_CONDITION;loopParameter++)
                   newTerm = Math.sqrt(2+previousTerm);
                   previousTerm = newTerm;
                   System.out.println(newTerm);
    }If you use it as a function, set it as
    public double vietaLoop(int noTerm)
    Then you can change no of term for looping.
    Regards
    John

  • Quick for loop question

    Hi everybody,
    I have a feeling this is so obvious that I'm missing it, so if anyone would give me some advice, I'd appreciate it.
    I have a method with with three parameters that loops through them and progressively adds or subtracts them with a for loop, based on the order. The only way I can think of to do this, though, is with two for loops with almost identical code. I know there must be an easier way to do this, but I think I've been staring at it too long, can anyone give me a hand conceptually, please?
    The method is:
    private void create( int param1, int param2 ) {
            int entries = 5;
            double increment;
            if( param1 > param2 ) {
                increment = param1 - param2;
                for( int i = 0; i < entries; i++ ) {
                    System.out.println( param1 - ( i * increment ) );
            } else if( param2 > param1 ) {
                increment = param2 - param1;
                for( int i = 0; i < entries; i++ ) {
                    System.out.println( param1 + ( i * increment ) );
         }Thanks,
    Jezzica85
    Edited by: jezzica85 on Mar 30, 2009 2:38 PM

    private void create( int param1, int param2 ) {
        if( param1 > param2 ) {
            create(param2, param1);
        } else if( param2 > param1 ) {
            int entries = 5;
            double increment = param2 - param1;
            for(int i = 0; i < entries; i++ ) {
                System.out.println( param2 + (i * param1));
        } //equal do nothing?
    }or
    private void create2( int param1, int param2 ) {
        if (param1 != param2) {
            int entries = 5;
            int minParam = Math.min(param1, param2);
            int maxParam = Math.max(param1, param2);
            double increment = maxParam - minParam;
            for( int i = 0; i < entries; i++ ) {
                System.out.println( maxParam - (i * minParam));
      }

  • Enhance for loop question

    I like it, but I can't figure out how to use it for the following situation (printing contents of two arrays using one iterator):
    old way:
            System.out.println(menuTitle + "/n");
            for (int e ; e < length.menuChoices ; e++)
                System.out.print(menuChoices[e] + " - " + menuLabels[e]);
            }new?
            System.out.println(menuTitle + "/n");
            for (String e : menuChoices)
                System.out.print(e + " - " + menuLabels[????]);
            }Is there a nice way to do this or should I just use the old for loop and hope my teacher doesn't think that I just don't know about the new loop? Thanks.

    Is there a nice way to do this or should I just use
    the old for loop and hope my teacher doesn't think
    that I just don't know about the new loop?No there isn't. In the new for-loop the loop counter has been abstracted away. You'll have to either use the old for-loop, or introduce a counter in the new.
    Another way could be to change the design a little.
    class MenueItem {
       Type1 choice();
       Type2 label();
    for (String e : menuItems)  { // all MenuItems
       System.out.print(e.choise() + " - " + e.label());
    }

  • 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

Maybe you are looking for