FOR loop termination?

Is there any way in LabView to terminate FOR loop from the inside
before it executes N times? Something like "break" instruction in C. It
seem like a simple question, but I couldn't find a simple solution :-).
thanks,
chris

I know this is not exactly what you are asking for, but I will mention it anyway.
There are two ways to stop a For Loop. The first is to use the auto-index like you are doing. The other is to wire a value to the N input before starting the
loop. The loop will stop on the first occurence of EITHER of these methods. If you want the convenience of auto-indexing, but know that you will not want to
process all of the values in the array, try to determine the quantity before entering the loop. Then wire that value to the N input. A value of 0 will prevent
any iterations of the loop from executing.
Good luck.
Michael Munroe Mailto:[email protected]
A Better Complete Development Engineering Firm
San Mateo, CA 94403 ht
tp://www.abcdefirm.com
chris szybinski wrote:
> this is exactly what I've done :-). But it would be much easier to be able to break the loop.
> chris
>
> Harry King wrote:
>
> > In article <[email protected]>,
> > chris szybinski wrote:
> > >yes it is,
> > >sometimes I need to run the loop 0 times. While Loop runs at lest one time, as the condition is checked at the end of the loop. One can build the logic to
> > >run a While Loop 0 times, but in my case design becomes pretty complicated.
> > >In other words I can accomplish what I want, but I hoped to simplify my VI.
> > >best regards,
> > >chris
> >
> > Perhaps you could put a select comparison function in there and send the
> > results to the loop? WHile false, it will not run, and while true, it
> > will. Just a thought without any background into your program.
> >
> > Harry
Michael Munroe, ABCDEF
Certified LabVIEW Developer, MCP
Find and fix bad VI Properties with Property Inspector

Similar Messages

  • Conditiona​lly Indexed For Loop Terminal

    Dear LabVIEW community!
    Most of you, I’m sure, know and use in LabVIEW 2012 such useful and helpful feature as conditional terminal in For Loop (see it on the picture below).
    But if one saves such code in previous versions of LabVIEW, then we see, that code has different look (VI Snippet was made in LV 2012, so don’t be confused – it is really code in LV 2011).
    The same algorithm is made by using case structure and shift register. But the problem is that this shift register is uninitialized (1) (we have some constant (2) on the block diagram after saving file in previous version, but it is wrong constant for our case), and you know, that it can cause unexpected behavior of the program. So, if you have to convert such a code to previous versions of LabVIEW, don’t forget to check it, and initialize that shift registers.
    Solved!
    Go to Solution.

    Wow! I had no idea this little "conditional terminal" existed. I've been doing Example B all this time, and it sometimes really causes my BDs to elongate. I don't know about you, but my programming always to contain the best examples of "The drawing will fill the space available - and then some." Now, I'll get to stick in one or two more bits before I hit the right-hand wall. Thanks.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Conditional Loop Terminal and Autogrow

    When changing a for loop terminal from indexing to conditional, the for loop and any containing structures expand even when they are not set to Auto Grow.
    When selecting multiple conditional tunnels and and choosing Vertical Compress from the Distribute Objects menu, the tunnels are compressed as if they don't have condititonal terminals.
    Are either of these bugs known or corrected in LabVIEW 2013?  I could not find anything on NI.com when searching for "conditional tunnel autogrow".
    Thanks,
    Matt
    Attachments:
    Conditional Terminal Auto Grow bug.vi ‏6 KB

    Matt,
    A Very nice example of unexpected behaviour!
    Steps to reproduce:
    Open Matt's attachment in LabVIEW 2012  (12.0f3 Windows 32 on Win 7 64)
    Right-click the loop and verify Autogrow is not checked
    Right-click the top output tunnel and select Tunnel mode>>Conditional.   Loop does not respect the autogrow setting! 
    Lasso both output tunnels and Ctrl+D (or optionally, click Distribute items>>Vertical Compress)  Conditional glyphs are not respected in allignment
    Select the "Top" tunnel and Ctrl+Shift+J (Move to back)  What kind of tunnel is that now? I'd really hate to debug that one.
    Really Really hate to debug that one! Run VI Analizer! No overlapping objects!
    Sounds like a small oversight-- but a deadly potential for breaking code that is impossible to find without a divining rod!
    BOLO (Be on the lookout) for this type of bug.
    Jeff

  • While loop and for loop condition terminal

    Hello friends,
    I am using labview 8.6. The condition terminal of the while loop and conditional for loop is behaving in just the opposite way.
    When i wire a true to the condition terminal of my loop, the while loop continues to run when I click on run. when I wire a FALSE, it stops.
    Is there any setting change that I have to make it to get it work properly.
    Please suggest on this.
    Thanks and regards,
    Herok

    Please do NOT attach .bmp images with the extension changed to .jpg to circumvent the forum filters!
    Herok wrote:
    I am sending you the VI. I am not sure if this would help you because only in 2 computers this behaviour is seen. In others, it works as it is supposed to work.
    Whatever you are seeing must be due to some corruption or folding error. It all works fine here.
    To make sure there are no hidden objects, simply press the cleanup button which would reveal any extra stuff (which is obviously not there). Does it fix itself if you click the termination terminal an even number of times? What if you remove the bad loop and create a new one?
    Could it be you have some problems with the graphics card and the icon of the conditional terminal does not update correctly?
    Whay happens if you connect a control instead of a diagram constant?
    What is different on the computers where it acts incorrectly (different CPU (brand, model), #of cores, etc.) 
    LabVIEW Champion . Do more with less code and in less time .

  • LabVIEW 6.1 If For Loop count terminal is zero then value going through the loop is not passed on to the output of the loop

    Hello, one of our customers just encountered an execution error in a vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or 6.01. I have a simple vi that has two encapsulated For Loops. Two string arrays go in, one goes out of the outer loop. Inside the outer loop the first array is indexed. The string which results from this indexing is compared with all other strings from the second string array in the inner loop. If it matches one of the strings of the second array, it is not outputted, otherwise this string goes through the inner For Loop to the output of the inner loop and from there to the output of the outer loop. The count
    terminal of the outer/inner loop is connected to the Array Size of the first/second string array. If the second array is empty, that means that the element in test from the first arry cannot match anything from the second array, so the element in test is send to the output of the inner loop and from there to the output of the outer loop. This works fine in LabVIEW 5.1 and 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never executed if the count value is zero (which is correct), but the data line running through the loop is not executed either, which is different to what LabVIEW 5.1 and 6.01 do. There, the input string is sent to the output of the inner loop correctly even if the loop counter is zero. The solution is easy - I just have to connect the output of the outer loop to the data line BEFORE it enters the inner loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is supposed to be a feature, but it brings some incompatibility in programming between the
    different LabVIEW versions.
    Best regards,
    Gabsi

    Hi,
    When a for-loop runs zero times, all outputs are 'undefined' (and should
    be).
    Besides, how would LV know what the output of a not executed routine should
    be?
    It might be handled differently in LV5 and LV6, which is unfortunate. In
    both cases, the result is undefined.
    It's not a bug. It's just something that should be avoided in any LV
    version.
    > The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    In some cases this does the trick. But if the data is changed in the inner
    loop, this will effect the results if the N is not zero.
    Technically, I think the output in this construction is also 'undefined'.
    But LV handles this as expected / desired.
    Another solution is to use a shift register. If N is zero, the input is
    directly passed through to the output.
    Regards,
    Wiebe.
    "Gabs" wrote in message
    news:[email protected]...
    > LabVIEW 6.1 If For Loop count terminal is zero then value going
    > through the loop is not passed on to the output of the loop
    >
    > Hello, one of our customers just encountered an execution error in a
    > vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or
    > 6.01. I have a simple vi that has two encapsulated For Loops. Two
    > string arrays go in, one goes out of the outer loop. Inside the outer
    > loop the first array is indexed. The string which results from this
    > indexing is compared with all other strings from the second string
    > array in the inner loop. If it matches one of the strings of the
    > second array, it is not outputted, otherwise this string goes through
    > the inner For Loop to the output of the inner loop and from there to
    > the output of the outer loop. The count terminal of the outer/inner
    > loop is connected to the Array Size of the first/second string array.
    > If the second array is empty, that means that the element in test from
    > the first arry cannot match anything from the second array, so the
    > element in test is send to the output of the inner loop and from there
    > to the output of the outer loop. This works fine in LabVIEW 5.1 and
    > 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never
    > executed if the count value is zero (which is correct), but the data
    > line running through the loop is not executed either, which is
    > different to what LabVIEW 5.1 and 6.01 do. There, the input string is
    > sent to the output of the inner loop correctly even if the loop
    > counter is zero. The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    > supposed to be a feature, but it brings some incompatibility in
    > programming between the different LabVIEW versions.
    > Best regards,
    > Gabsi

  • 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

  • For loop stop in sub vi from main vi?

    Hi! I want to control from my main vi a sub vi consisting of a stepped sine function generator. This sub vi has a for loop. The problem is that I want to have the option of terminating the loop in the sub vi from the main vi. I tryed using global variables or an event stucture. The problem is that, in both cases, the "stop" variable in my main vi is only updated after the loop terminates in the sub vi. Can anyone please help me? Thank you very much.
    Best regards,
    Diogo Montalvão (Lisbon, Portugal)

    hong2011 wrote:
    I found this thread very helpful. May I ask one thing - what is the purpose of the Occurrence?? If I try it without implementing the Occurrence (neither in main VI or subVI), labview crashes when the subVI completes its task or is stopped from the mainVI.
    A lot of things changed in the last 6 years, so this thread is a bit stale and there are a few other ways to do it. (For example we can have a FOR loop with a conditional terminal).
    You don't provide enough information to answer your question why it crashes. It would be more interesting to know what you are "using" and not what you are "not using". This is not something we can guess by elimination.
    LabVIEW should never crash, so please show us the code that crashes so NI can fix it. What LabVIEW version are you using?
    LabVIEW Champion . Do more with less code and in less time .

  • For loop- seems to be just going to last value

    Hi guys, carrying on from the thread I created yesterday I have managed to get the socket working between my server and my client, but I am having an issue when re-constructing a string that is being sent from the client to the server. I am talking about the for loop in line 151, which seems to just going straight to the last value of the for loop and thus the board isn't being reconstructed properly.
    I'm including both the server and client code which just needs to compiled (host is set to localhost on port 4500) and you will see what I mean after inputting a move from the client. Can anyone spot the problem?
    Server code
    import java.io.*;
    import java.net.*;
    import javax.swing.JOptionPane;
    class Server
         public static void main (String []args) throws IOException
              try
                   Server();     
              catch (IOException ex)
         public static void Server () throws IOException
              ServerSocket serverSocket=null;
              int portNo=4500;
              System.out.println("Starting");
              try
                   serverSocket=new ServerSocket(portNo);     
              catch (IOException ex)
                   System.err.println("Could not create socket on port" +portNo);
                   System.exit(1);
              System.out.println("Socket listening");
              Socket clientSocket=null;
              try
                   clientSocket=serverSocket.accept();
              catch (IOException ex)
                   System.out.println("Accept failed");
                   System.exit(1);
              PrintWriter out= new PrintWriter(clientSocket.getOutputStream(), true);
              BufferedReader in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
              //coordinates
              String coordinates[] [] = new String [8] [8];
              for (int i=0;i<8;i++)
                   for (int j=0;j<8;j++)
                        if ((i%2!=0)&&(j%2!=0))
                             coordinates[i] [j]="#";
                        else if ((i%2!=0)&&(j%2==0))
                             coordinates[i] [j]=" ";
                        else if ((i%2==0)&&(j%2!=0))
                             coordinates[i] [j]=" ";
                        else
                             coordinates[i] [j]="#";
              coordinates[0][0]="R";
              coordinates[0][1]="N";
              coordinates[0][2]="B";
              coordinates[0][3]="Q";
              coordinates[0][4]="K";
              coordinates[0][5]="B";
              coordinates[0][6]="N";
              coordinates[0][7]="R";
              for (int i=0;i<8;i++)
                   coordinates[1]="P";
              coordinates[7][0]="r";
              coordinates[7][1]="n";
              coordinates[7][2]="b";
              coordinates[7][3]="q";
              coordinates[7][4]="k";
              coordinates[7][5]="b";
              coordinates[7][6]="n";
              coordinates[7][7]="r";
              for (int i=0;i<8;i++)
                   coordinates[6][i]="p";
              Board board1=new Board(coordinates);
              boolean gameStart=true;
              String coord="";
              String originX="";
              String originY="";
              String destinationX="";
              String destinationY;
              while (gameStart)
                   System.out.println("trying to read from client");
                   String input="";
                   try
                        input=in.readLine();     
                        System.out.println(input);
                   catch (IOException ex)
                        System.out.println("Read failed");
                        System.exit(1);
                   originX=input.substring(65);
                   originY=input.substring(66);     
                   destinationX=input.substring(67);
                   destinationY=input.substring(68);
                   coord=input.substring(0,64);
                   System.out.println(coord);
                   for (int p=0;p<64;p++)
                        System.out.println(p);
                        for (int i=0;i<8;i++)
                             for (int j=0;j<8;j++)
                                  coordinates [i] [j]=coord.substring(p);
                                  if (i==(Integer.parseInt(originX))&&(j==(Integer.parseInt(originY))))
                                       String piece="";
                                       piece=coordinates [i] [j];
                                       if ((i%2!=0)&&(j%2!=0))
                                            coordinates[i] [j]="#";
                                       else if ((i%2!=0)&&(j%2==0))
                                            coordinates[i] [j]=" ";
                                       else if ((i%2==0)&&(j%2!=0))
                                            coordinates[i] [j]=" ";
                                       else
                                            coordinates[i] [j]="#";
                                       for (int s=0;s<8;s++)
                                            for (int t=0;t<8;t++)
                                                 if (s==(Integer.parseInt(destinationX))&&(t==(Integer.parseInt(destinationY))))
                                                      coordinates [s] [t]=piece;
                   board1.printBoard(coordinates);
              out.close();
              in.close();     
              clientSocket.close();
              serverSocket.close();          
    class Board
         boolean gameStart=true;
         public Board()
         public Board(String [] [] coordinates)
              printBoard(coordinates);
         String [] [] getCoOrdinates(String [] [] coordinates)
              return coordinates;
         public static void update (String coordinates [] [])
              printBoard(coordinates);
         public static void printBoard(String coordinates[] [])
              for (int i=0;i<8;i++)
                   for (int j=0;j<8;j++)
                        System.out.print(coordinates[i][j]);
                   System.out.println();
    }Client code:import java.io.*;
    import java.net.*;
    import javax.swing.JOptionPane;
    class Client
         public static void main (String [] args) throws IOException
              Socket socket=null;
              PrintWriter out=null;
              BufferedReader in=null;
              String serverLocation="localhost";
              int portNo=4500;
              System.out.println("Starting");
              try
                   socket= new Socket (serverLocation,portNo);
                   out= new PrintWriter(socket.getOutputStream(),true);
                   in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
              catch (UnknownHostException ex)
                   System.out.println("Cannot find" + serverLocation);
                   System.exit(1);     
              catch (IOException ex1)
                   System.out.println("IO problem");
                   System.exit(1);
              System.out.println("Connected");
              //coordinates
              String coordinates[] [] = new String [8] [8];
              for (int i=0;i<8;i++)
                   for (int j=0;j<8;j++)
                        if ((i%2!=0)&&(j%2!=0))
                             coordinates[i] [j]="#";
                        else if ((i%2!=0)&&(j%2==0))
                             coordinates[i] [j]=" ";
                        else if ((i%2==0)&&(j%2!=0))
                             coordinates[i] [j]=" ";
                        else
                             coordinates[i] [j]="#";
              coordinates[0][0]="R";
              coordinates[0][1]="N";
              coordinates[0][2]="B";
              coordinates[0][3]="Q";
              coordinates[0][4]="K";
              coordinates[0][5]="B";
              coordinates[0][6]="N";
              coordinates[0][7]="R";
              for (int i=0;i<8;i++)
                   coordinates[1][i]="P";
              coordinates[7][0]="r";
              coordinates[7][1]="n";
              coordinates[7][2]="b";
              coordinates[7][3]="q";
              coordinates[7][4]="k";
              coordinates[7][5]="b";
              coordinates[7][6]="n";
              coordinates[7][7]="r";
              for (int i=0;i<8;i++)
                   coordinates[6][i]="p";
              Board board1=new Board(coordinates);
              boolean gameStart=true;
              String coord="";
              while (gameStart)
                   String originMove=JOptionPane.showInputDialog(null,"Client Origin Move","Enter in origin of piece",JOptionPane.QUESTION_MESSAGE);
                   String destinationMove=JOptionPane.showInputDialog(null,"Client Destination Move","Enter in destination of piece",JOptionPane.QUESTION_MESSAGE);
                   for (int i=0;i<8;i++)
                        for (int j=0;j<8;j++)
                             coord=coord+coordinates[i][j];
                   System.out.println(coord);
                   out.println(coord+originMove+destinationMove);
                   System.out.println("passed");
              out.close();
              in.close();
              socket.close();
    class Board
         boolean gameStart=true;
         public Board()
         public Board(String [] [] coordinates)
              printBoard(coordinates);
         String [] [] getCoOrdinates(String [] [] coordinates)
              return coordinates;
         public static void update (String coordinates [] [])
              printBoard(coordinates);
         public static void printBoard(String coordinates[] [])
              for (int i=0;i<8;i++)
                   for (int j=0;j<8;j++)
                        System.out.print(coordinates[i][j]);
                   System.out.println();
    }Cheers,
    Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    jverd wrote:
    p595659 wrote:
    1) I don't think that even compiles. Since you're catching IOException, your throws clause is bogus--that method can never throw IOE.I have removed the try and catch statements in the main method. I cannot, however get rid of the throws IOException in the main method other my program won't compile.Right. Don't catch it, since you're not handling it. Just declare that it throws it.
    Indeed, this is what I have done :)
    >
    3) Don't name methods the same as your class name.See answer to 4.
    4) Start method names with lowercase letters.
    try
    serverSocket=new ServerSocket(portNo);     
    catch (IOException ex)
    System.err.println("Could not create socket on port" +portNo);
    System.exit(1);
    ServerSocket is a part of the java.net package. I am just creating an instance of it. http://java.sun.com/j2se/1.4.2/docs/api/java/net/ServerSocket.html
    I don't know what you're talking about. You had a class named Server and a method named Server. That's confusing.Changed- I didn't spot it, so I have named it startServer now.
    >
    5) There's almost no point to ever calling System.exit. Here, again, since you're not
    actually handling the exception, don't bother catcing it.Sorry, but this was how I was taught when I started java. My understanding is that System.exit properly terminated applications so this freed up memory so it's abit of a habit of mine, is this wrong to do in this instance?Calling it in response to an exception is wrong. It's not that method's job to decide to shut down the VM. Just let the exception bubble up (or else handle it properly). You do not need to call System.exit to free up memory. It's freed up automatically when the VM exits. The OS takes care of that, without any help from you.Removed- thanks for clearing that up for me :)
    JacobsB wrote:
    line 151 of the server code or client code?Line 151 of my server code. My client is working fine up to this step of the programming I have done- it's just the server part I'm having issues with. You can compile and run the client fine- you can compile the server but as explained in the original post, I'm having a logical error when redrawing the board when it gets the 68 charecter string from the client (first 64 charecters are for the board, then the original position (x and y respectively), followed up the new position (x and y respectively again).
    I'm including an updated version of the code, after all the comments above so we have an updated version for trying to solve the problem I'm having. The client code does not need to be updated as it has not changed yet, so you can use the code in the original post.
    import java.io.*;
    import java.net.*;
    import javax.swing.JOptionPane;
    class Server
         public static void main (String []args) throws IOException
              startServer();     
         public static void startServer () throws IOException
              ServerSocket serverSocket=null;
              int portNo=4500;
              System.out.println("Starting");
              try
                   serverSocket=new ServerSocket(portNo);     
              catch (IOException ex)
                   System.err.println("Could not create socket on port" +portNo);
                   ex.printStackTrace();
              System.out.println("Socket listening");
              Socket clientSocket=null;
              try
                   clientSocket=serverSocket.accept();
              catch (IOException ex)
                   System.out.println("Accept failed");
                   ex.printStackTrace();
              PrintWriter out= new PrintWriter(clientSocket.getOutputStream(), true);
              BufferedReader in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
              //coordinates
              String coordinates[] [] = new String [8] [8];
              for (int i=0;i<8;i++)
                   for (int j=0;j<8;j++)
                        if ((i%2!=0)&&(j%2!=0))
                             coordinates[i] [j]="#";
                        else if ((i%2!=0)&&(j%2==0))
                             coordinates[i] [j]=" ";
                        else if ((i%2==0)&&(j%2!=0))
                             coordinates[i] [j]=" ";
                        else
                             coordinates[i] [j]="#";
              coordinates[0][0]="R";
              coordinates[0][1]="N";
              coordinates[0][2]="B";
              coordinates[0][3]="Q";
              coordinates[0][4]="K";
              coordinates[0][5]="B";
              coordinates[0][6]="N";
              coordinates[0][7]="R";
              for (int i=0;i<8;i++)
                   coordinates[1]="P";
              coordinates[7][0]="r";
              coordinates[7][1]="n";
              coordinates[7][2]="b";
              coordinates[7][3]="q";
              coordinates[7][4]="k";
              coordinates[7][5]="b";
              coordinates[7][6]="n";
              coordinates[7][7]="r";
              for (int i=0;i<8;i++)
                   coordinates[6][i]="p";
              Board board1=new Board(coordinates);
              boolean gameStart=true;
              String coord="";
              String originX="";
              String originY="";
              String destinationX="";
              String destinationY;
              while (gameStart)
                   System.out.println("trying to read from client");
                   String input="";
                   try
                        input=in.readLine();     
                        System.out.println(input);
                   catch (IOException ex)
                        System.out.println("Read failed");
                        ex.printStackTrace();
                   coord=input.substring(0,64);                    
                   originX=input.substring(64,65);
                   originY=input.substring(65,66);     
                   destinationX=input.substring(66,67);
                   destinationY=input.substring(67,68);
                   System.out.println(coord);
                   for (int p=0;p<64;p++)
                        System.out.println(p);
                        for (int i=0;i<8;i++)
                             for (int j=0;j<8;j++)
                                  coordinates [i] [j]=coord.substring(p);
                                  if (i==Integer.parseInt(originX)&&(j==(Integer.parseInt(originY))))
                                       String piece="";
                                       piece=coordinates [i] [j];
                                       if ((i%2!=0)&&(j%2!=0))
                                            coordinates[i] [j]="#";
                                       else if ((i%2!=0)&&(j%2==0))
                                            coordinates[i] [j]=" ";
                                       else if ((i%2==0)&&(j%2!=0))
                                            coordinates[i] [j]=" ";
                                       else
                                            coordinates[i] [j]="#";
                                       for (int s=0;s<8;s++)
                                            for (int t=0;t<8;t++)
                                                 if (s==(Integer.parseInt(destinationX))&&(t==(Integer.parseInt(destinationY))))
                                                      coordinates [s] [t]=piece;
                   board1.printBoard(coordinates);
              out.close();
              in.close();     
              clientSocket.close();
              serverSocket.close();          
    class Board
         boolean gameStart=true;
         public Board()
         public Board(String [] [] coordinates)
              printBoard(coordinates);
         String [] [] getCoOrdinates(String [] [] coordinates)
              return coordinates;
         public static void update (String coordinates [] [])
              printBoard(coordinates);
         public static void printBoard(String coordinates[] [])
              for (int i=0;i<8;i++)
                   for (int j=0;j<8;j++)
                        System.out.print(coordinates[i][j]);          
                   System.out.println();
    }Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is there a way to change the i of for loop

    Hello,
    A Labview question. A tusk should be repeat 10 times in a for loop. so the value of i in the for loop will be changed from 0 to 9. Sometimes, some tusks may repeat one extra time. It there a way to let me change the value of i in the for loop?
    Thanks a lot
    Solved!
    Go to Solution.

    the i terminal will always output the iteration number (0 through 9 in your case).  But there's nothing that says you can't perform some weird math or use case structure with it.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to stop and start a for loop

    I've got code and a for loop running in a while loop.  What I need to do is simply pause the operation of the for loop until an requirement is met, and but maintain its iteration position throughout each pause interval (not necessarily timed, just paused until the next requirement is met).  I've tried wiring a boolean to the "continue if true" terminal of the for loop, but the iteration count restarts to 0 when the loop is started again.  Is there a way to stop the for loop, and continue at the particular iteration it is at?
    Solved!
    Go to Solution.

    Breakpoints, whether normal or conditional, are just meant for debugging of your code.  I had the sense from your question that the pausing you want to do is a part of normal operation of your code.  I would NOT recommend using a breakpoint for that situation.  It would bring up the block diagram showing the breakpoint when it occurs.  A user besides the programmer would not know what to do in that case.
     Yes, both the inner and outer loops would have shift registers.
    Putting a case structure with a small while loop inside the "Pausing Case" is doable.  It just depends on what you are doing or waiting for while the program operation is "paused".

  • 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

  • Strange System.out.print behavior inside a for loop

    I'm trying to create a simple ASCII progress bar in the console that would display like this:
    |--------------------------------------------|
    ============================More equal signs would appear as time goes on. At least this is what I want to happen.
    Instead, what happens is, none of the equal signs are printed until the very end, after the for loop in which the System.out.print("=") statement is in, has exited.
    This is my code (probably more than necessary is shown, but the important part is the for loop):
        public void addSomeDiffys(int numOfDiffys, int minInt, int maxInt) {
            Diffy currentDiffy;
            System.out.println("\nCreating Diffys.");
            System.out.println("|--------------------------------------------|");
            for (int i=0; i < numOfDiffys; i++) {
                currentDiffy = new Diffy(minInt, maxInt);
                if ((i/(double)numOfDiffys)*100 % 2 == 0)
                    System.out.print("=");
                diffyList.add(currentDiffy);           
            System.out.println("\n" + diffyList.size() + " Diffys created.\n");
            System.out.println("Sorting according to highest rating...");
            Collections.sort(diffyList,Diffy.HIGHEST_RATING_ORDER);
            System.out.println("Done.\n");
        }I also tried changing the System.out.print("="); to System.out.println("="); This time it works as expected, its just not very pretty...
    I get something like this:
    |--------------------------------------------|
    =
    =
    =
    =
    =
    =
    =
    =
    =
    =
    =
    =So again, when I use println, rather than print, the equal signs are printed over time, slowly, as the progress increases. When using print, Nothing happens for a long time, and then suddenly they all appear after the for loop has terminated, which makes no sense.
    Thanks for any help.

    When using print, Nothing happens
    for a long time, and then suddenly they all appear
    after the for loop has terminated, which makes no
    sense.
    Yes it does make sense! The characters are buffered inside the PrintStream and written when there is a full line to write. You could try a flush() after each = is written but I have no confidence that it will make any difference.

  • Unable to put a timed structure in a parallel for loop, error -808

    If I try to place a Timed Structure in a Parallel For Loop, the TS needs a different structure name per instance to prevent collisions. However, setting the Structure Name node  to something unique per instance doesn't work, I get error -808. Have I missed something?
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

    That got me thinking - something to do with the number of compiled parallel instances.
    Indeed, the compiler creates a number of parallel instances of the for loop in the compiled code (in my case 8), and uses the number requested at the Parallel Instances terminal (just under the Iterations terminal), which is set to 2. Therefore the compiler has created 8 instances of the Timed Structure, each in its own for loop instance, but they all have the same defined Structure Name. When launched, there is an immediate conflict because they can't share the same name, and error -808 is launched before the set Structure Name function can change it. Hence the error still shows when requesting only one instance, because the other seven still exist.
    I guess this means you can't have Timed Structures (or Timed Loops for that matter too) in a Parallelised For Loop?
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

  • How to create parallel tasks using parallel for loops

    Hi,
    I am setting up a program that communicates with six logic controllers and has to read the system status every 100 ms. We are using OPC datasockets for this, and they appear a little slow. 
    I have created a uniform comm. method for all controllers, and now I find myself programming this method six times to communicate with each system. I am wondering if this could be done more elegant using the parallel for loop, in which case I would program an exchange once and then have six workers running simultaneously. Since a picture is more clear that a thousand words, what I am asking is this:
    Is it possible to replace something like
    by
    and have this for loop running these tasks in parallel (on different cores / in different threads)?
    I have configured the loop to create 8 instances at compile, so I would have 2 instances surplus available at runtime if I find I need an additional system.
    The benefits of the method show in the second picture to me are:
    * takes less space
    * modifications have to be made only once
    * less blocks, wires and stuff makes it more clear what's going on.
    * flexibility in the actual number of tasks running (8 instances available at runtime)
    * if more tasks are required, I need only to update the maximum number of instances and recompile, i.e. no cutting and pasting required. 
    Unfortunately, I don't have those system available yet, so there's no way to test this. Yet, I would like to know if the above works as I expect - unfortunately the labview help is not completely clear to me on this.
    Best regards,
    Frans 
    Solved!
    Go to Solution.

    Dear mfletcher,
    First of all: thanks for confirming that my intuition was right in this case.
    As for your question on the help: below is a copy/paste from the help on the 'configure parallelism dialog box' 
    Number of generated parallel loop instances—Determines the number of For Loop instances LabVIEW generates at compile time. The Number of generated parallel loop instances should equal the number of logical processors on which you expect the VI to execute. If you plan to distribute the VI to multiple computers, Number of generated parallel loop instances should equal the maximum number of logical processors you expect any of those computers to ever contain. Use the parallel instances terminal on the For Loop to specify how many of the generated instances to use at run time. If you wire a larger number to the parallel instances terminal than you specify in this dialog box, LabVIEW only executes as many loop instances as you specify here.The reason for me doubting if what I programmed would work the way I intended lies in the fact that the help only mentions processors here, which would be interpreted as actual cores. Thus on a dual core machine, the number should be 2.
    I think it would be helpful to mention something about threads here, because in some case one would like to have more parallel threads than there are cores in a system.
    In mu case I would like to create six threads, which on my dual core processor would be spread over only two cores. Then these six threads run in parallel.I know that in case of heavy math that would not help, but since I am doing communications, which have timeouts and such, and that probably runs smoother in six parallel tasks even though I only have two cores. 
    Hope this helps in improving the help of the for loop.
    Regards,
    Frans 

  • For Loop with Error Check

    Hello all,
    As per my sample VI.
    I gave   Empty array to For Loop. As we know this Loop will not execute because N value “0”.
    But, I want to know why Error out always giving True value. This Error Indicator value changing to “True” irrespective of Error In.  
     BR,
    Munna
    Munna
    Solved!
    Go to Solution.

    That''s exaclty what I said.
    If you use plain tunnels and the loop iterates zero times, the output will give the default value for the datatype, which is FALSE for errors.
    If you use shift registers, whatever is wired to the initializer terminal will be output unchanged on the right if the loop iterates zero times. Since you initialize with a error=TRUE, that's what you get.
    This is all as expected. In your first post you claimed that the output is error=true using plain tunnels, which cannot be. Agreed?
    If you want error=false with the shift register, change the diagram constant accordingly.
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for