While Loop Coding

I have code where I am using a "while" statement. As long as the User presses the number 1 on the keyboard, the program loops back to the start, which is perfect, that is what I want. If a User press the number 0 on the keyboard, the program should stop and ... this is the part of the "while loop" that I don't understand how to code. Below is the "While Loop" that I have, as well as the ending line.
public static void main(String[] args)
String another ="1";
while (another.equals("1"))
.....NOW WHAT?......AS YOU CAN SEE, MY LOOP IS INCOMPLETE. I DON'T KNOW HOW TO CODE THE 0 PORTION.
...at the bottom after the System.out.Prinln() I have the following line of code:
another = Console.readString("To place another order press(1). Press 0 to quit? ");
Of course, the number 1 works but the 0 doesn't.
Help and thanks.

>
public static void main(String[] args)
String another ="1";
while (another.equals("1"))
.....NOW WHAT?......AS YOU CAN SEE, MY LOOP IS
INCOMPLETE. I DON'T KNOW HOW TO CODE THE 0 PORTION.
...at the bottom after the System.out.Prinln() I have
the following line of code:
another = Console.readString("To place another order
press(1). Press 0 to quit? ");
Of course, the number 1 works but the 0 doesn't.
You're right in principal. You don't have to do anything about checking 0, though it might be a good idea. So I reckon there's a syntax problem with the bit we're not seeing.
If while controls more than one statement they have to be enclosed in curly brackets if you miss this it'll loop on the next statement only which, since it doesn't change your another will run forever.
Incidentally a loop that runs at least once is better coded using the do .. while construct.
I'd code it something like:
String keepGoing = null;
do {
   .... do your thing
   for(;;) {   // this is a "middle exit" loop
            // without the break it would run forever
      keepGoing = Console.readString("More to do? (Entery 0 or 1):").trim();  // trim removes spaces
      if(keepGoing.equals("0") || keepGoing.equals("1"))
           break;  // exit inner loop if valid
      keepGoing = Consile.readString("Eh?? Must be 0 or 1:");
   // now we know we have "0" or "1"
   } while(keepGoing.equals("1"));

Similar Messages

  • How to export a continous waveform data from a while loop?

    Hello there,
    I need to add noise signal to my waveform which is read from a binary file. I use noise generate vi (deleted the density part) from NI example as my sub VI, and put it into a while loop in order to get the continous noise signal, but I don't know how to export this data. There's no waveform come out from the noise waveform output tunnel (on the while loop). I used output tunnel, didn't work, tried shift register, didn't work... Can anybody help?
    Also, how to fix the dt problem for the noise generate vi and my original data ( from binarty file)
    Thanks in advance!
    Wendy

    hi
    I think notifier can do the trick (an example is shown in the master-slave template).
    Another possibility can be a FG (or action engine, look for the nugget ActionEngine, it will change your LV-coding life !)
    N

  • While Loop Freezes game

    i am coding for GTA IV
    the game freezes when i use this while loop
    while (tb == true)
    if (Game.isKeyPressed(begkey) && ip == false)
    beg_playing();
    Game.Console.Print(begkey.ToString() + " Pressed");
    Game.Console.Print("Animation Cleared");
    Player.Character.Task.ClearAllImmediately();
    Player.Character.Task.PlayAnimation(beggarsitting, "beggar_beg", 8);
    Game.Console.Print("beggar_beg anim played");
    ip = true;
    gmoney.Start();
    while (bp == true) { Wait(100); }
    gback();
    return;
    if (Player.Character.isDead)
    cleanup();
    Here is the full code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Diagnostics;
    using System.Collections.Generic;
    using GTA;
    using GTA.Native;
    namespace Beggar
    public class ambBeggar : Script
    bool tb = false;
    bool bp = true;
    bool ip = false;
    Ped rped;
    AnimationSet beggarsitting;
    //AnimationSet beggarstanding;
    Keys begkey;
    GTA.Timer gmoney;
    public ambBeggar()
    gmoney = new GTA.Timer(120000);
    gmoney.Tick += gmoney_Tick;
    begkey = Settings.GetValueKey("Beg", "Beggar Mod", Keys.B);
    if(!File.Exists(Settings.Filename))
    Settings.SetValue("Beg", "Beggar Mod", Keys.B);
    this.Interval = 100000;
    this.Tick += new EventHandler(ambBeggar_get);
    this.ConsoleCommand += new ConsoleEventHandler(ambBeggar_ConsoleCommand);
    public void ambBeggar_get(object sender, EventArgs e)
    if(tb == true && !rped.Exists())
    rped = World.GetClosestPed(Player.Character.Position,20);
    public void gmoney_Tick(object sender, EventArgs e)
    if (rped.Exists())
    rped.Task.GoTo(Player.Character.Position.Around(2));
    Pickup.CreateMoneyPickup(rped.Position, 1000);
    rped.NoLongerNeeded();
    ip = false;
    if(gmoney.isRunning)
    gmoney.Stop();
    public void ambBeggar_ConsoleCommand(object sender, ConsoleEventArgs e)
    if (e.Command == "beggar_on")
    tb = true;
    Game.Console.Print("Beggar Mod By Mora Hannover");
    Game.Console.Print("beggar mod toggled");
    //Function.Call("REQUEST_ANIMS", "amb@beg_sitting");
    Game.Console.Print("loading anim set amb@beg_sitting");
    beggarsitting = new AnimationSet("amb@beg_sitting");
    Wait(5000);
    //Function.Call("REQUEST_ANIMS","amb@beg_standing");
    // if (Function.Call<bool>("HAVE_ANIMS_LOADED", "amb@beg_sitting") && Function.Call<bool>("HAVE_ANIMS_LOADED","amb@beg_sitting"))
    Game.Console.Print("amb@beg_sitting available");
    msg("Press " + begkey.ToString() + " To Beg", 5000);
    //beggarstanding = new AnimationSet("amb@beg_standing");
    Player.Character.Animation.Play(beggarsitting, "beggar_sit", 8, AnimationFlags.Unknown05);
    Game.Console.Print("beggar_sit anim played");
    while (tb == true)
    if (Game.isKeyPressed(begkey) && ip == false)
    beg_playing();
    Game.Console.Print(begkey.ToString() + " Pressed");
    Game.Console.Print("Animation Cleared");
    Player.Character.Task.ClearAllImmediately();
    Player.Character.Task.PlayAnimation(beggarsitting, "beggar_beg", 8);
    Game.Console.Print("beggar_beg anim played");
    ip = true;
    gmoney.Start();
    while (bp == true) { Wait(100); }
    gback();
    return;
    if (Player.Character.isDead)
    cleanup();
    if (e.Command == "beggar_off")
    cleanup();
    public void msg(string sMsg, int time)
    Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", new Parameter[] { "STRING", sMsg, time, 1 });
    public void beg_playing()
    if (GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "amb@beg_sitting", "beggar_beg") == false)
    bp = false;
    if (GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "amb@beg_sitting", "beggar_beg") == true)
    bp = true;
    public void cleanup()
    tb = false;
    ip = false;
    bp = false;
    Game.Console.Print("beggar_mod off :'(");
    Player.Character.Task.ClearAllImmediately();
    if(gmoney.isRunning)
    gmoney.Stop();
    public void gback()
    Player.Character.Task.ClearAllImmediately();
    Player.Character.Task.PlayAnimation(beggarsitting, "beggar_sit", 8, AnimationFlags.Unknown05);
    Game.Console.Print("beggar_sit anim played"); return;

    Hello,
    Have you tried to debug your code step by step? As it's very hard for others to reproduce your problem, I recommend that you firstly debug your code, find out which line causes the problem. And make sure that you don't cause infinit loop in your code, as
    I can see from your code, if the variable "tb" or "bp" is always true, your code will go into an infinit loop. This will cause the freeze of the application.
    while (tb == true)
    if (Game.isKeyPressed(begkey) && ip == false)
    beg_playing();
    Game.Console.Print(begkey.ToString() + " Pressed");
    Game.Console.Print("Animation Cleared");
    Player.Character.Task.ClearAllImmediately();
    Player.Character.Task.PlayAnimation(beggarsitting, "beggar_beg", 8);
    Game.Console.Print("beggar_beg anim played");
    ip = true;
    gmoney.Start();
    while (bp == true) { Wait(100); }
    gback();
    return;
    if (Player.Character.isDead)
    cleanup();
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Timing with while loop

    Hello,
    How can I do a time with while loop?. I want to read a data in the While- Loop for 1 sec and then go to B .. I added a pic,
    Attachments:
    while- loop.GIF ‏6 KB

    nichts wrote:
    Hello,
    How can I do a time with while loop?. I want to read a data in the While- Loop for 1 sec and then go to B .. I added a pic,
    I would use as GerdW has mentioned,"elapsed time.vi" in a statement 1st case structure, after set time has elapsed> goto 2nd case structure. try not to use flat sequences....this can be done with case statements with transitional coding. I have noticed young LV programmers like to use flat sequences...I think it's a trap set up by LV developers? 

  • Help needed with while loops please :)

    I'm beginning to study java at School.
    My assignment using while loops, to ask user to input 2 numbers.
    I have to output all odd number between the two.
    I have to output the sum of all even numbers between the two.
    Output all the numbers and their squares between 1-10.
    Output the squares of the odd numbers between the 2 numbers the user entered.
    Output all uppercase letters.
    If anyone can give me any help, I would appreciate it greatly.
    Thank you.
    Kelly.

    It would help if you put aside your code, and wrote out some pseudo-code first so that you understand the steps you will need to take. for example
    get input from user
    set counter to first number entered
    while counter less than/ equal to second number
          check if number is even
               if even, add to even_sum
               else output counter, along with its square
          increment counter by one
    end while
    output sum of evensthat block, when coded, will solve 3 of the problems, the other 2 will require separate loops
    Good Luck

  • Problems with a while loop within a method... (please help so I can sleep)

    Crud, I keep getting the wrong outputs for the reverseArray. I keep getting "9 7 5 7 9" instead of "9 7 5 3 1". Can you guys figure it out? T.I.A (been trying to figure this prog out for quite some time now)
    * AWT Sample application
    * @author Weili Guan
    * @version 1999999999.2541a 04/02/26
    public class ArrayMethods{
       private static int counter, counter2, ndx, checker, sum, a, size, zero;
       private static int length;
       private static int [] output2, output3, reverse, array;
       private static double output;
       private static double dblsum, dblchecker, average;
       public static void main(String[] args) {
          //int
          //int [] reverse;
          System.out.println("Testing with array with the values [1,3,5,7,9]");
          size = 5;
          array = new int [size];
          reverse = new int [size];
          array[0] = 1;
          array[1] = 3;
          array[2] = 5;
          array[3] = 7;
          array[4] = 9;
          System.out.println("Testing with sumArray...");
          output = sumArray(array);
          System.out.println("Sum of the array: " + sum);
          System.out.println();
          System.out.println("Testing with countArray...");
          output = countArray(array);
          System.out.println("Sum of the elements : " + checker);
          System.out.println();
          System.out.println("Testing with averageArray...");
          output = averageArray(array);
          System.out.println("The average of the array : " + average);
          System.out.println();
          System.out.println("Testing with reverseArray...");
          output2 = reverseArray(array);
          output3 = reverseArray(reverse);
          //System.out.print(reverse[4]);
          System.out.print("The reverse of the array : ");
          for(ndx = 0; ndx < array.length; ndx++){
             System.out.print(reverse[ndx] + " ");
       private ArrayMethods(){
       public static int sumArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if (array[ndx] > 0){
                checker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                sum += array[ndx];
                ndx++;
             return sum;
          else{
             sum = 0;
             return sum;
        /*Computes the sum of the elements of an int array. A null input, or a
        zero-length array are summed to zero.
        Parameters:
            array - an array of ints to be summed.
        Returns:
            The sum of the elements.*/
       public static int countArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if(array[ndx] > 0 && array[ndx] != 0){
                checker++;
             counter++;
          return checker;
        /*Computes the count of elements in an int array. The count of a
        null reference is taken to be zero.
        Parameters:
            array - an array of ints to be counted.
        Returns:
            The count of the elements.*/
       public static double averageArray(int[] array){
          dblchecker = 0;
          ndx = 0;
          counter = 0;
          dblsum = 0;
          while(counter < array.length){
             if(array[ndx] > 0){
                dblchecker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                dblsum += array[ndx];
                ndx++;
             average = dblsum / dblchecker;
             return (int) average;
          else{
             average = 0;
             return average;
        /*Computes the average of the elements of an int array. A null input,
        or a zero-length array are averaged to zero.
        Parameters:
            array - an array of ints to be averaged.
        Returns:
            The average of the elements.*/
       public static int[] reverseArray(int[] array){
          ndx = 0;
          counter = 0;
          counter2 = 0;
          if(array.length == 0){
             array[0] = 0;
             return array;
          else{
                //reverse = array;
             while(ndx <= size - 1){
                   reverse[ndx] = array[4 - counter];
                   counter++;
                   ndx++;
                   System.out.print("H ");
          return reverse;
        /*Returns a new array with the same elements as the input array, but
        in reversed order. In the event the input is a null reference, a
        null reference is returned. In the event the input is a zero-length array,
        the same reference is returned, rather than a new one.
        Parameters:
            array - an array of ints to be reversed.
        Returns:
            A reference to the new array.*/
    }

    What was the original question? I thought it was
    getting the desired output, " 9 7 5 3 1."
    He didn't ask for improving the while loop or the
    reverseArray method, did he?
    By removing "output3 = reverseArray(reverse):," you
    get the desired output.Okay, cranky-pants. Your solution provides the OP with the desired output. However, it only addresses the symptom rather than the underlying problem. If you'd bother yourself to look at the overall design, you might see that hard-coding magic numbers and returning static arrays as the result of reversing an array passed as an argument probably isn't such a great idea. That's why I attempted to help by providing a complete, working example of a method that "reverses" an int[].
    Removing everything and providing "System.out.println("9 7 5 3 1");" gets him the desired output as well, but (like your solution) does nothing to address the logic problems inherent in the method itself and the class as a whole.

  • While loop issue

    I've been working on this assignment for a few days and got through my problem with the IF/ELSE IF statement. Now I am running into a problem with what I assume is some poor coding of my WHILE loops.
    I have this data file to input and read from:
    40      Light Karen L
    81       Fagan Bert Todd
    60       Antrim Forrest N
    95       Camden Warren
    52       Mulicka Al B
    89        Lee Phoebe
    75      Bright Harry
    92      Garris Ted
    43      Benson Martyne
    100       Lloyd Jeanine D
    73      Leslie Bennie A
    70      Brandt Leslie
    89      Schulman David
    90      Worthington Dan
    70      Hall Gus W
    50      Prigeon Dale R
    63      Fitzgibbons RustyMy code is as such:
    import java.io.*;
    import java.util.*;
    public class prgrm8
    { public static void main(String [] args) throws Exception
    { Scanner inFile = new Scanner(new FileReader("prgrm8.dat"));
         PrintWriter outFile = new PrintWriter("prgrm8.out");
              int value, ctr = 0, ctrR = 0;
              double sum = 0;
              String name = " ";
              String line = " ";
              String msg = " ";
              String filename = "prgrm8.dat";
              StringTokenizer st;
              outFile.println("REPORT");
         while(inFile.hasNextLine())
              line = inFile.nextLine();
              st = new StringTokenizer(line);
              value = Integer.parseInt(st.nextToken());
              name = st.nextToken();
         while(st.hasMoreTokens())
              name = name + " " + st.nextToken();
              st = new StringTokenizer(name);
              ctr++; 
         if(value >= 90){      
                   msg = "OUTSTANDING";
         }else{
         if(value >= 70){
                        msg = "Satisfactory";                                   
                         sum += value;
                        ctrR++;
         }else{
                        msg = "FAILING";
              outFile.println(value + " " + name + " " + msg);
              outFile.println(ctr + " " + "processed names");
              outFile.println(ctrR + " " + "between 70 and 89 inclusive");
         if(ctrR <= 0)
              outFile.close();
    }and I am outputing the following to my outFile:
    REPORT
    63 Fitzgibbons Rusty FAILING
    1 processed names
    0 between 70 and 89 inclusiveSo I am validating when compiling now, but I am not getting the intended results( I am wanting output each students grade, name, and the corresponding message, then get the total number of names processed(ctr), and then the number of grades between 70 and 79(ctrR) . Any advice is helpful, and thanks in advance!

    Here
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.Reader;
    import java.io.StreamTokenizer;
    import java.util.HashMap;
    public class Prog8 {
        public static void main(String[] args) {
            HashMap<String, Integer> map = new HashMap<String, Integer>();
            Reader r = null;
            StreamTokenizer st = null;
            PrintWriter pw = null;
            try {
                r = new BufferedReader(new FileReader("prgrm8.dat"));
                st = new StreamTokenizer(r);
            st.lowerCaseMode(false);
            st.eolIsSignificant(false);
            st.slashSlashComments(false);
            st.slashStarComments(false);
            String s = null;
            int i = 0;
                while (st.nextToken() != StreamTokenizer.TT_EOF) {
                    switch (st.ttype) {
                    case StreamTokenizer.TT_NUMBER:
                        i = (int) st.nval;
                        break;
                    case StreamTokenizer.TT_WORD:
                        s = st.sval;
                        break;
                    if (!map.containsKey(s) && !map.containsValue(i)) {
                        map.put(s, i);
                    } else {
                        System.err.println("Record already exist.");
                pw = new PrintWriter("prgrm8.out");
                int j = 0, k = 0, l = 0;
                for (String string : map.keySet()) {
                    if (map.get(string) >= 90) {
                        pw.println(map.get(string) + " " + string + "OUTSTANDING");
                        j++;
                    } else if (map.get(string) <= 89 && map.get(string) >= 70) {
                        pw.println(map.get(string) + " " + string + "PASSING");
                        k++;
                    } else {
                        pw.println(map.get(string) + " " + string + "FAILING");
                        l++;
                pw.println(j + " OUTSTANDING, " + k + " PASSING, and " + l + " FAILING");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    pw.flush();
                    pw.close();
                    r.close();
                } catch (IOException e) {
                    e.printStackTrace();
    }P.S. untested
    let me know.
    Edited by: Oclamora on May 15, 2010 6:56 PM
    spelling edit

  • While loop error

    I can't seem to find the soultion to the following error message:
    G:\UOP\POS 406\Java Assignements\Week 3, Assignment 2\MortgageCalcV1.java:53: variable option might not have been initialized
                   while ((option == 'Y') || (option == 'y'))
                   ^
    1 error
    Tool completed with exit code 1
    The following is my code starting with the while line to the end of while statement:
    //While statement to prompt user to continue to use calculator or to quit.
                   while ((option == 'Y') || (option == 'y'))
                   {  //begin loop
                        System.out.print("Enter the amount to be financed: $");
                        StrPrincpal = dataIn.readLine (); //Places data into the string StrPrincpal
                        princpal = Double.parseDouble (StrPrincpal);
                        System.out.println();
                        System.out.print("Enter the rate: ");
                        StrIntRate = dataIn.readLine (); //Places data into the string StrPrincpal
                        IntRate = Double.parseDouble (StrIntRate);
                        System.out.println();
                        System.out.print("Enter the term of the loan: ");
                        StrTerm = dataIn.readLine (); //Places data into the string StrPrincpal
                        term = Integer.parseInt (StrTerm);
                        System.out.println();
                        //Calculation
                        rate = (IntRate / 100.0) / 12.0;     // converts % to decimal format
                        Calpymt = rate + 1;                         // calculate interest
                        term = 30*12;                              // calculate number of years to number of months
                        pymt = princpal * (Math.pow(Calpymt, term) * rate)/ (Math.pow (Calpymt, term) -1);      // formula to calculate monthly payment
                        System.out.println("\nMonthly payment will be: " + moneyFormat.format(pymt) + "\n");  // outputs monthly payment to screen
                        System.out.println("Date of report:" + currentDate);
                       System.out.println("\n");  // create a blank line after output
                       //User response required y or n to refresh the calculator to perform another calculation
                       System.out.println("Do you wish to calculate another mortgage?\n");
                       System.out.print("Please Enter Y or N:\t");
                       System.out.println("\n");
                   option = (char)System.in.read();
                             //StrResponse = dataIn.readLine();
                             //option = Character.parseChar(StrResponse);
                             //}  //close while loop
                   } //close loopI have defind variable as char option;
    Thanks for any assistance you can give me on this issue.

    This is quite common in novice coding. Especially if it's for a uni assignment ;)
    The important thing is that you take the time to understand what the compiler is trying to tell you.
    on line 53, the variable "option" is compared to 'Y'. However, if you have only declared "option":-
    char option;
    as opposed to:-
    char option = OPTION_DEFAULT_VALUE;
    The Java compiler cannot compile the program if "option" might not have been initialised. If "option" isn't initialised, you'll get an exception when you try to enter the while loop.
    Initialise option with a default value before the logic that sets it occurs.
    And try to understand what the compiler is telling you.

  • Cursors vs while loop

    Hi,
    We know cursors are evil, use lot of memory, adds up tempdb activity, not scalable, hinders concurrency etc...Say if I replace 10 heavily used cursors in OLTP system with while loops how much do I gain if any and
    how can I measure that. How can I convince my code review DBA to make this change? Does this change help the server?

    The big gains (orders of magnitude) will come by changing cursors to set-based statements as you've done. If you can avoid row-by-row looping (through cursors or otherwise), then you should see some good gains there as well. In SQL Server 2005's CTEs and MARS we've removed some of the remaining need to use cursors and loops. But there are some situations where row-by-row processing still seems to be needed, and performing some non-set-based statement for a set of rows is the primary example .. executing a DBCC command for each database, for example.
    If you find you are calling a stored proc for each row, perhaps you can pass a table containing the rows into the stored proc (perhaps by using a temp table) and then use set-base operations inside the stored proc, but there are times when you just need to call the sp row by row. If, after investigating all the set-based alternatives, you find you really do have to process rows one by one, then cursors are one way of iterating through a set of rows, and they do provide some good functionality with a well-defined behavior and you'll probably use your cursor together with a WHILE loop.
    If you don't use a cursor to hold the rows to process, you'll have to retrieve a single row yourself each time through the loop; that'll probably be more coding for you, increase the potential for more bugs in your code, perhaps be more costly during execution, etc. So the trade-off becomes one of using cursors with a known downside, versus custom code with other potential drawbacks.
    I'd say the "change cursors to while loops" statement oversimplifies the situation and falls way below the "change cursors to set-based operations where possible" primary guideline .. and it's unfortunate that it's at the top of the list in the article you mention.
    Don

  • How to use one single boolean button to control a multiple while loops?

    I've posted the attached file and you will see that it doesn't let me use local variable for stop button, but I need to stop all the action whenever I want but more than one single button on the front panel would look ugly... The file represents the Numeric Mode of
    HP 5371A. thanks for your time
    Attachments:
    NUMERIC.vi ‏580 KB

    In order to use a local variable, you can change the mechanical action of stop button (Switch When Pressed will work), or create a property node for it and select values. You'll also have to do a lot of work changing those for loops into while loops so that you can abort them.

  • While loop doing AO/AI ... Performanc​e?

    Hi!
    I have been trying to get a VI to do concurrent Analog
    data in and out and both the input and output rates and
    waveforms can change while the VI is running. My problem
    is this:
    (a) If I try putting the read and write operations in
    separate while loops, one or the other loop will
    die in a buffer over/underrun.
    (b) If I put both into the same loop, then this works
    but I am limited in the choice of data-rate parameters
    because eventually one or the other DAQ VI will take
    too long.
    At this point I have only one loop and the buffers are big
    enough to hold 10 iteration. Every time one of the loops
    dies I reset it. Still this seems awkward. Is there a
    way of improving on the loop overhead and putting t
    he
    input and output in separate loops? Or any other way to
    improve performance?
    Rudolf

    Ok, I knew that ocurences did something useful but I am
    still a bit confused:
    * Can you set an occurrence for an output event. None
    of the examples I've seen say so but it looks like
    it should work
    * How do occurrences actually help with the "hanging"
    problem. Does the compiler see the occurrence in
    a loop and change the wait parameters?
    I looked at devzone but most of the stuff I found there,
    even the promising looking stuff was all about
    synchronizing and triggering, not about occurrences.
    Rudolf
    JB wrote:
    : Once in the read function, the program "hangs" until the number of
    : data points is in the buffer. The same applies to the write function.
    : This means that most of the time, your program is waiting.
    : To sol
    ve this problem, you must use DAQ occurrences (--> hardware
    : events).
    : For examples for using daq occurrences, type "daq occurrence" in the
    : search of the LabVIEW help or even better, at
    : http://zone.ni.com/devzone/devzoneweb.nsf
    : Hope this helps

  • Can not pass data after while loop

    Hello.
    I have created a VI for my experiment and am having problem passing data outside a while loop to save on an excel file. The VI needs to first move a probe radially, take data at 1mm increment, then move axially, take data radially at 1mm increment, then move to the next axial position and repeat. It would then export these data to an excel file. The VI is a little complicated but it's the only way I know how to make it for our experiment. I have tested it and all the motion works correctly, however I can not get it to pass the data after the last while loop on the far right of the VI where I have put the arrows (Please see the attached VI ). Is it because I'm using too many sequence, case, and while loops?  If so, what other ways can I use to make it export data to the excel file?
    Any help would be appreciated. 
    Thank you,
    Max
    Attachments:
    B.Dot.Probe.Exp.vi ‏66 KB

    Ummmm .... gee, I'm not even sure where to begin with this one. Your VI is well .... ummmm... You have straight wires! That's always nice to see. As for everything else. Well... Your fundamental problem is lack of understanding of dataflow programming. What you've created is a text program. It would look fantastic in C. In LabVIEW it makes my heart break. For a direct answer to your question: Data will not show up outside a while loop until the while loop has completed. This means your most likely problem is that the conditions to stop that specific loop are not being met. As for what the problem is, I don't even want to start debugging this code. Of course, one way to pass data outside of loops is with local variables, and hey, you seem to be having so much fun with those, what's one more?
    This may sound harsh, and perhaps be somewhat insulting, but the brutal truth is that what I would personally do is to throw it out and to start using a good architecture like a state machine. This kind of framework is easy to code, easy to modify, and easy to debug. All qualities that your code seems to lack.
    Message Edited by smercurio_fc on 08-17-2009 10:00 PM

  • Why writes LabVIEW only every 2 seconds the measured Value to a Excel (In a while loop with 100 ms tact)?

    Hi everybody,
    I use the myDAQ to measure speed, ampere, and voltage of a battery driven motor. (For Current measurement, i use a Sensor which outputs a 0-10 V signal). I placed all DAQ-Assitants in a while loop with a [Wait until next ms multiple] clock and set a value of 100 ms. I thougt, Labview will now write into my text file 10 times a second all values. In fact, as you can see in the attached text file, Labview only writes in a unsteady interval of 1-2 seconds a value, which is too less.
    The question: Did I do anything wrong, how can you create VI that writes you lets say 10 values a second into text file? Or is simply the DigitalMultimeter input of the myDAQ not able to sample a rate of 10 Hz? I couldn´t find any information in the specification handbook about the sample rate of the DMM?
    If anyone can help me would be great! Thanx a lot, Markus
    Attachments:
    Measure Speed+Current+Voltage into Excel.vi ‏175 KB
    Test7.txt ‏1 KB

    File I/O is not very efficient. I recommend that you do you file logging in a parallel task. Have one task do your data acquision. This task would then pass the data to be logged to the logging task via a queue. That way your file operations do not impact your data acquision. Also, express VIs are not very efficient. You would be better off accessing that directly using the DAQ VIs. The express VIs contain lots of steps that do not need to be done every time you call it such as initializing the device.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How can I reset the value of an indicator in a while loop, from another synchronous while loop?

    I am running 2 synchronous while loops, one which is keep track of time, and the other is measuring periods. In the while loop that is measuring periods, I have a boolean indicator displaying whether the signal is on or off. My problem is that when the signal is off, the VI I use to measure the periods is waiting for the next signal, and displays the boolean value from the previous period measurement. While this VI is waiting, I want the indicator to display false and not the value from the last iteration of the loop.
    I am using LV 5.1 for MAC.

    Two things you can try:
    In preface to the first, the most common (perhaps ONLY) use of local variables should be in transferring data between parallel loops. This is a matter of discipline, and creates programs that are easier to understand, take less time and memory, and are just plain cleaner. Having said that, to transfer data between loops, use a local variable.
    Second solution: Instead of setting the value to false, just hide the indicator in question by using control references (property nodes for prev. version of LabVIEW). Control references are a great way to control items on a dialog or HMI screen.

  • Sir i am using datasocket read ,i am communicating with java but my problem is that bcz im using while loop to see if value has changed my labview consumes all the processors time ,sir i want a event like thing so that while loop is not in continuous loop

    sir i have given lot of effort but i am not able to solve my problem either with notifiers or with occurence fn,probably i do not know how to use these synchronisation tools.

    sir i am using datasocket read ,i am communicating with java but my problem is that bcz im using while loop to see if value has changed my labview consumes all the processors time ,sir i want a event like thing so that while loop is not in continuous loopHi Sam,
    I want to pass along a couple of tips that will get you more and better response on this list.
    1) There is an un-written rule that says more "stars" is better than just one star. Giving a one star rating will probably eliminate that responder from individuals that are willing to anser your question.
    2) If someone gives you an answer that meets your needs, reply to that answer and say that it worked.
    3) If someone suggests that you look at an example, DO IT! LV comes with a wonderful set of examples that demonstate almost all of the core functionality of LV. Familiarity with all of the LV examples will get you through about 80% of the Certified LabVIEW Developer exam.
    4) If you have a question first search the examples for something tha
    t may help you. If you can not find an example that is exactly what you want, find one that is close and post a question along the lines of "I want to do something similar to example X, how can I modify it to do Y".
    5) Some of the greatest LabVIEW minds offer there services and advice for free on this exchange. If you treat them good, they can get you through almost every challenge that can be encountered in LV.
    6) If English is not your native language, post your question in the language you favor. There is probably someone around that can help. "We're big, we're bad, we're international!"
    Trying to help,
    Welcome to the forum!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • Iphone 4 can't hear me, but I hear them

    My iphone 4 I can hear them, but they can't hear me. They can hear me on speaker and they can hear me with my Bluetooth. This happened a couple of months ago. I went to the Apple store. They told me that the moisture indicator was orange at the botto

  • Using scan from string to convert a string into a number

    I wanted to use scan from string to change a string into a decimal number, but when the string is, for example, 9.14123E-2 it just returns 10. How can I get it to return .00914 or 9.14E-2(as a number not a string). Would there be something easier tha

  • Gray lines above video after exporting as quicktime. IMAGES inside.

    After I export my footage as a quicktime film I get this gray lines above my footage. They change around in different scenes. Is it because I forgot to do something before exporting? http://img822.imageshack.us/img822/6364/picture4ly.png http://img68

  • Problem on JTable Sorting

    Hi, I am using JDK1.6 and I am using the predefined sorter function for sorting the JTable, here I am getting the trouble that My JTable get the Table List from a server, when ever I connect to the server its giving me the list of records, after that

  • Why System.arraycopy(srcarray,destarray,destpos,length)

    Hi, In the quest for writing an application that uses an int array the changes its length very often, I still find myself wondering why Sun did not add a few simple methods to work directly on the primitive arrays. Mehtods such as add(), delteat(pos)