Infinite While-loop!

Hey there! I'm trying to do some data input validation but I haven't been able to figure it out. First I need to check if the user entered anything, that one works. Then I need to check if what the user entered was a number. But I'm getting an infinite while loop in when I try to validate if the first character entered is a letter. . . .
Thanks for your help!
public class methods
public static void main(String args[]) throws IOException
  String input ="";
  int qoh=0;
  boolean error=true;
  Scanner keyboard = new Scanner (System.in);
  //while (error)
                //   error=true;
                        while (error==true)
                            System.out.print("\nEnter Quantity on Hand: ");
                            input = keyboard.nextLine();
                            if (input.length() <1)
                                System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
                                error=true;
                                System.out.println(qoh);
                                System.out.println(input);
                            else
                                error=false;
                        error = true;
                        while (error==true)
                            if (Character.isLetter(input.charAt(0)))
                                System.out.println("\n**ERROR06** - Quantity on hand must be between 0 and 500");
                                error=true;
                                System.out.println(qoh);
                                System.out.println(input);
                            else
                                qoh = Integer.parseInt(input);
                                error=false;
        }

1. add in breakpoints to your program.
Eg. put print statements before and after loops to confirm which loop is producing the inf loop error.
also add in print statements in your if and else blocks.
2. You should consider using keyboard.next() instead of nextLine()
Eg. how are you going to handle "500 orange crush"?
3. I have a feeling that the real problem lies at the 2nd loop where you tried to do a parseInt
What happens if you have "5lmao" charAt(0) check is passed, but it wont produce a int will it?
You might want to loop through every char in the input string to confirm they are a number.
4. I suggest
If(input.length() > 0) error = false
else print msg
OR
assume no errors before loop.
if(length() <1) error=true
else error = false
5. use the keyword "break". By that i mean set up your loop to be infinite loops, use the break operator under specified condition (error=false)
I didn't identify the error for you, but i'd say the above methods should help you with your problem

Similar Messages

  • How to out from infinite while loop in sub VI

    Dear Sir,
    how to out from infinite while loop in sub VI from main VI
    attached photo for solution but I can't understand it and i can't find the function in photo 
    please help
    Attachments:
    stop_subVI_frm_main.JPG ‏36 KB

    Asking how to get out of an infinite loop is like asking how to find the end of a circle. I'm not trying to be sarcastic but by definition, if there is a way out of the loop, then it is not infinite. I think what you are asking is how to avoid creating an infinite loop. Is there something about the suggestions you have been given that you do not like? My favorite suggestion is the notifier but maybe you just need an example. Turn on context help and read about the notifier functions in the code below.
    This is your top level VI
    And this is your subVI
    If this seems too complex then a global variable will work too. But what seems simpler can cause much more complex bugs. You can code fast and spend lots of time debugging or you can code slow and spend less time debugging. Personally I perfer writing productive code than looking for bugs any time.
    =====================
    LabVIEW 2012

  • UI flickrs continously jdk1.7.25 EventdispatchThread's pumpEventsForFilter goes to infinite while loop

    I am migrating a project from Java 1.3 to Java 1.7 update 25 and there is one search button functionality in which search is performed correctly but the UI flickers continuously because EventdispatchThread's pumpEventsForFilter goes to infinite while loop.
    This same code works correctly in java 1.3.
    Below is the part of the code related to searchbutton. Can you please suggest regarding this because the issue is within java api and not sure how to solve this.
    SearchButton.java:
    private JButton searchButton; 
    private String textsearchButton = 
          search.util.Language.getString("buttonStartSearch"); 
    searchButton = new JButton(textsearchButton); 
    buttonPanel.add(searchButton); 
    searchButton.addActionListener(this); 
    searchButton.addActionListener(actionListener); 
    actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "toFront")); 
                actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "searchComplete")); 
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 
        if (hasSearch) { 
                actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "searchComplete")); 
             else { 
                actionListener.actionPerformed( 
                   new ActionEvent( 
                      searchButton, 
                      ActionEvent.ACTION_PERFORMED, 
                      "search")); 
    searchButton.setEnabled(!hasSearch && hasCriterions()); 
    public void actionPerformed(ActionEvent ae) { 
          Object source = ae.getSource(); 
          else if (source == searchButton) 
             startSearch(); 
          else if (source == exportButton) 
             exportSearch(); 
          else { // ActionEvents from the panels occur 
             changesOccured(); 
    EventDispatchThread:
    void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) { 
            addEventFilter(filter); 
            doDispatch = true; 
    //This while goes to infinite loop 
           [b] [color=red]while (doDispatch && !isInterrupted() && cond.evaluate()) { 
                pumpOneEventForFilters(id); 
            }[/color][/b] 
            removeEventFilter(filter); 

    Please provide your code example as SSCCE . I'm not going to spent time guessing what your application code (other than shown) meigt do or not do.
    bye
    TPD

  • Stuck inside an infinite While Loop :-/

    Hi all,
    When I write this program using the top-down structural method, it runs fine but when I use the call method inside the while loop, it doesn't test the "if" condition. It becomes a never-ending loop. :-/
    import java.util.Random;
    public class WhileLoop {
          public static void main(String[] args) {
            int random1;
            Random die1 = new Random();
            random1 = die1.nextInt(6) + 1;
            WhileLoop r = new WhileLoop();
            while (random1 != 5) {
              if (random1 != 5) {
               r.doRandom();
              if (random1 == 5) {
                System.out.println("you win! ");
             int random1;
          public void doRandom() {
             Random die1 = new Random();
             random1 = die1.nextInt(6) + 1;
             System.out.println("random1 = " + random1);
      }If I replace the line " r.doRandom(); " with " random1 = die1.nextInt(6) + 1; System.out.println("random1 = " + random1); " the program will check the "if" condition and stops when it finds the number 5. What's wrong with my code?
    Thanks for your help.

    DrLaszloJamf wrote:
    {color:#3D2B1F }You have two, unrelated variables that happen to both be named random1.{color}Opps! Must have missed it. Using two unrelated variables with the same name was, unintentional ~ //yea, right (blush). Thanks for pointing it out. :-)
    Encephalopathic wrote:
    you never change random1 from within the while loop. You think you do, but it's a different random1 that you're changing, a non-static one that is an instance variable.okay~ but does it mean that 'random1' from the method within the while-loop cannot be used for comparison purpose? I tried using a 'return' value from the doRandom method and use that value inside the "if" condition, but it also does not terminate the loop. The only way it's going to work is by using the solution DrLaszlo gave? Is there any other way to do this by using a call method?
    Thanks!

  • Infinite "while" loop subshell loses current date variable

    I have a simple script to log network connectivity to a set of systems.
    However, as expected the date appended to the log never changes because the new variable is lost when the loop starts again. Can someone clue me in on how to get around this issue?
    #!/bin/bash
    LOG=/tmp/netlog
    when=`/bin/date`
    while true;
    do
    for server in srv1 srv2 srv3 srv4 srv5;
    do
    ping -c 1 $server > /dev/null
    if [ $? -ne 0 ]; then
    echo "$server-DOWN!" $when >> $LOG.$server
    # mail
    else
    echo "$server-UP!" $when >> $LOG.$server
    fi
    done
    done

    esa wrote:Jason, from my experience, [] with quotes around variables is generaly more cross-over compatible (bsd'ish, deb'ish, rh'ish) than [[]] without quoting of variables.
    More than once i've had unexpected behaviour caused by using [[ condition ]].
    That's why you'd use /bin/bash instead of /bin/sh .. (or rather /usr/bin/env bash - OpenBSD has bash in /usr/local/bin) - [[ is bash specific.
    http://mywiki.wooledge.org/Bashism
    Last edited by Alad (2015-05-21 13:01:27)

  • Infinite for loop to load images

    I hope to load repeat images until user close the browser.
    But I find it is hard to use infinite loop to make it.
    Is there any other way to do it ??
    Thanks a lot
    for (;;){     <=================================== ???
    //jpeg = (String) session.getValue("JPEG");
    //int jpeg_ch = Integer.parseInt(jpeg,10);
    session.putValue("JPEG_NO",String.valueOf(jpeg_no));
    //int jpeg = (int)((Math.random()*123456789)%16);
    %>
    <img style="position: absolute; left:<%= x[jpeg_no] %>; top:<%= y[jpeg_no] %>; width: 160; height:120;" Src="http://192.168.10.110:8080/servlet/Servlet?jpeg=<%= jpeg_no %>">

    for(;;) is an infinite for loop
    while(true) is an infinite while loop
    please post your URL so that I can make sure to avoid going to this page. I certainly don't want the page to constantly be loading images forever.

  • While loop in query is going under infinite loop

    Declare
    @StartDate_in date,
    @EndDate date
    Set @StartDate_in = cast('2000-01-01' as date)
    Set @EndDate = cast('2010-12-31' as date)
    declare @month int
    declare @year int
    declare @endyear int
    declare @startdate date
    set @startdate= @startdate_in
    set @month = month(@StartDate_in)
    set @year= year(@StartDate_in)
    set @endyear= year(@EndDate)
    while @year<=@endyear
    Begin
    while month(@startdate)<=12 and @year<=@endyear
    begin
    print (@year);
    print (month(@startdate));
    INSERT Into target
    ( YEAR,
    MONTH,
    MONTH_VAL,
    L_DT,
    U_DT,
    S_DT,
    E_DT
    Values
    ( datepart(yyyy,@StartDate) ,
    datepart(month,@StartDate) ,
    substring(datename(month,@StartDate),1,3),
    GETDATE(),
    GETDATE(),
    (GETDATE()-1),
    null
    set @StartDate = dateadd(month,1,@StartDate);
    set @month=1;
    end
    set @year=@year+1;
    print (@year);
    print (@month);
    end
    The query although with exit condtion given in the while loop is not ending and executing infinetly
    ddl of target
    CREATE TABLE target(
    [TIME_ID] [int] IDENTITY(1,1) NOT NULL,
    [START_DT] [date] NULL,
    [E_DT] [date] NULL,
    [L_DT] [datetime] NULL,
    [U_DT] [datetime] NULL,
    [YEAR] varchar (5) NULL,
    [MONTH] varchar(5) NULL,
    [MONTH_VAL] [varchar](5) NULL
    ) ON [PRIMARY]
    GO
    Mudassar

    Try followings:Declare
    @StartDate_in date,
    @EndDate date
    Set @StartDate_in = cast('2000-01-01' as date)
    Set @EndDate = cast('2010-12-31' as date)
    declare @month int
    declare @year int
    declare @endyear int
    declare @startdate date
    declare @innerloopyear int
    set @startdate= @startdate_in
    set @month = month(@StartDate_in)
    set @year= year(@StartDate_in)
    set @endyear= year(@EndDate)
    set @innerloopyear = @year
    while @year<=@endyear
    Begin
    while month(@startdate)<=12 and @year>=@innerloopyear
    begin
    print (@year);
    print (month(@startdate));
    INSERT Into target
    ( YEAR,
    MONTH,
    MONTH_VAL,
    L_DT,
    U_DT,
    S_DT,
    E_DT
    Values
    ( datepart(yyyy,@StartDate) ,
    datepart(month,@StartDate) ,
    substring(datename(month,@StartDate),1,3),
    GETDATE(),
    GETDATE(),
    (GETDATE()-1),
    null
    set @StartDate = dateadd(month,1,@StartDate);
    set @innerloopyear = YEAR(@startdate)
    set @month=1;
    end
    print 'hello'
    set @year=@year+1;
    --set @StartDate = DATEADD(year,1,@StartDate)set @innerloopyear = @year
    print (@year);
    print (@month);
    end
    I have formatted change in "Bold".

  • While loop and data acquisition timing worries

    Hello everyone, 
    I apologize in advance if this is a silly question, but I could not find the answer around here. 
    I have made a VI to record continuously from 64 analog channels at a 5kHz sampling rate. I then stream this data to a tdms file. The data acquisition and write functions are in a while loop. 
    I the same loop, I have a bunch of other loops, that each run on their own wait timers to help limit the amount of memory they take up. I am now worried that this may somehow affect my data acquisition timing.
    If I put a bunch of timed loops within another loop, does the outer loop run at the same pace as the slowest of the inner loops? And could that mess up my sampling rate?
    I have attached my VI, in case what I just wrote makes no sense at all. 
    Thanks for any tips...
    Attachments:
    Record_M8viaDAQv3.vi ‏237 KB

    Well, looking at your code you will only write to your TDMS file one time. You have multiple infinite loops within the main/outer loop. That means that the main loop will only run a single iteration because it cannot complete an iteration until all code within it completes. With at least two infinite loops inside the loop it will never complete. Not too mention the only way to stop your code is to hit the stop/abort button. NOt a very good way to stop your code. As someone once said using the abort to stop your code is like using a tree to stop your car. It will work but not advised.
    As Ben mentioned try to understand data flow better. You have unnecessary sequence frames in your code where normal data flow will control the execution sequence.
    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 get the while loop to enter a different loop beside the first one

    I can't seem to figure out how to change the value to enter into one of the other while statements in the script. I am new to this and can't seem to find anything how to enter in the information to be able to go to different while statements and then run
    what is located in that statement.
    The script is supposed to let me choose between TC, MonsterLock, and Cyc and then jump to the while statement that is associated with one of them and then run what ever is located in that block. All i am getting is a infinite loop and it never sees the other
    while loops. I have 3 set up the go along with the first statement but no matter what i type in for them it always looks at the first while statement and stays there.
    Can someone please help me with having it do what i stated earlier.  
    write-host "This script sets up DATABASE Staging"
    $ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(TC/MonsterLock/Cyc)"
    While($ProductionDistro -notmatch "(TC|MonsterLock|Cyc)"){
    write-host "You have entered an error" -ForegroundColor Red
    write-host "You must type TC or MonsterLock or Cyc"
    write-host "you typed $ProductionDistro"
    write-host "This script sets up DATABASE Staging"
    $ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(TC/MonsterLock/Cyc)"
    while($ProductionDistro -match $TC) {
    write-host "Sets up location you want to run staging"
    $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
    While($ElementDistro -notmatch "(DATABASE1|DATABASE2|DATABASE3|DATABASE4|ALL)") {
    write-host "you have enterd an error" -ForegroundColor Red
    write-host "You must type DATABASE1 or DATABASE2 or DATABASE3 or DATABASE4 or ALL"
    write-host "you typed $ElementDistro"
    write-host "set location you want to run staging"
    $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
    While($PrductionDistro -match $MonsterLock){
    write-host "Sets up location you want to run staging"
    $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
    While($ElementDistro -notmatch "(DATABASE1|DATABASE2|DATABASE3|DATABASE4|ALL)") {
    write-host "you have enterd an error" -ForegroundColor Red
    write-host "You must type DATABASE1 or DATABASE2 or DATABASE3 or DATABASE4 or ALL"
    write-host "you typed $ElementDistro"
    write-host "set location you want to run staging"
    $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
    while( $ElementDistro -match $DATABASE1 ){
    function Execute-MySqlcommand {param( [string]$Server, #the host of the SQL server
    [string]$Database1, #the name of the database
    [System.Data.MySqlclient.MySqlcommand]$Command) #the command to execute (name of stored command)
    $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
    $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE1.DATABASE1S2.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE1.DATABASE1S3.BTXSUPB"
    $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE1.DATABASE1S2.BTXADDR;TRUNCATE TABLE DATABASE1.DATABASE1S3.BTXSUPB; INSERT INTO DATABASE1.DATABASE1S3.BTXSUPB SELECT * FROM DATABASE1.DATABASE1S2.BTXSUPB; select count(*) from DATABASE1.DATABASE.BTXADDR; select count(*) from DATABASE1S.DATABASE.BTXADDR; select count(*) from DATABASE1.DATABASE.BTXSURB; select count(*) from DATABASE1S.DATABASE.BTXSUPB;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $mysqlConnection
    $mysqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $mysqlConnection.Close()
    if ($Result -gt 0) {return $True} else {return $False}
    function Execute-MySQLCommand {param( [string]$Server, #the host name of the SQL server
    [string]$DATABASE1, #the name of the database
    [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)
    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "DATABASE_CONNECT_STRING=DSN=DATABASE1;Description=DATABASE1;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE1;DATASET=DEFAULT"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $sqlConnection
    $sqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $sqlConnection.Close()
    if ($Result -gt 0) {return $TRUE} else {return $FALSE}
    function Copy-File {
    #.Synopsis
    # Copies all files and folders in $source folder to $destination folder, but with .copy inserted before the extension if the file already exists
    param}($DATABASE0980453.pkg,"d/DATABASE1/code_stg")
    # create destination if it's not there ...
    #mkdir $destination -force -erroraction SilentlyContinue
    foreach($original in ls $source -recurse) {
    $result = $original.FullName.Replace($source,$destination)
    while(test-path $result -type leaf){ $result = [IO.Path]::ChangeExtension($result,"copy$([IO.Path]::GetExtension($result))") }
    if($original.PSIsContainer) {
    # mkdir $result -ErrorAction SilentlyContinue
    # } else {
    copy $original.FullName -destination $result
    cd /d/DATABASE1/code_stg
    install ../DATABASE0980453.pkg
    while($ElementDistro -match $DATABASE2 ) {
    function execute-MySqlcommand {param( [string]$Server, #the host of the SQL server
    [string]$DataBase2, #the name of the database
    [System.Data.MySqlclient.MySqlcommand]$Command) #the command to execute (name of stored command)
    $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
    $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE2.DATABASE2MS2.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE2.DATABASE2S3.BTXSUPB"
    $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE2.DATABASE2S2.BTXADDR;TRUNCATE TABLE DATABASE2.DATABASE2S3.BTXSUPB; INSERT INTO DATABASE2.DATABASE2S3.BTXSUPB SELECT * FROM DATABASE2.DATABASE2S2.BTXSUPB; select count(*) from DATABASE2.DATABASE.BTXADDR; select count(*) from DATABASE2S.DATABASE.BTXADDR; select count(*) from DATABASE2.DATABASE.BTXSURB; select count(*) from DATABASE2S.DATABASE.BTXSUPB;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $mysqlConnection
    $mysqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $mysqlConnection.Close()
    if ($Result -gt 0) {return $True} else {return $False}
    function Execute-MySQLCommand {param( [string]$Server, #the host name of the SQL server
    [string]$DATABASE2, #the name of the database
    [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)
    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "DATABASE_CONNECT_STRING=DSN=DATABASE2; Description=DATABASE2; Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE2;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $sqlConnection
    $sqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $sqlConnection.Close()
    if ($Result -gt 0) {return $TRUE} else {return $FALSE}
    function Copy-File {
    #.Synopsis
    # Copies all files and folders in $source folder to $destination folder, but with .copy inserted before the extension if the file already exists
    param}($DATABASE0980453.pkg,"d/DATABASE2/code_stg")
    # create destination if it's not there ...
    #mkdir $destination -force -erroraction SilentlyContinue
    foreach($original in ls $source -recurse) {
    $result = $original.FullName.Replace($source,$destination)
    while(test-path $result -type leaf){ $result = [IO.Path]::ChangeExtension($result,"copy$([IO.Path]::GetExtension($result))") }
    if($original.PSIsContainer) {
    # mkdir $result -ErrorAction SilentlyContinue
    # } else {
    copy $original.FullName -destination $result
    cd /d/DATABASE2/code_stg
    install ../DATABASE0980453.pkg
    While( $ElementDistro -match $DATABASE3 ) {
    function Execute-MySqlcommand {param( [string]$Server, #the host of the SQL server
    [string]$DATABASE3, #the name of the database
    [System.Data.MySqlclient.MySqlcommand]$Command) #the command to execute (name of stored command)
    $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
    $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE3.DATABASE3S2.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE3.DATABASE3S3.BTXSUPB"
    $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE3.DATABASE3S2.BTXADDR;TRUNCATE TABLE DATABASE3.DATABASE3S3.BTXSUPB; INSERT INTO DATABASE3.DATABASE3S3.BTXSUPB SELECT * FROM DATABASE3.DATABASE3S2.BTXSUPB; select count(*) from DATABASE3.DATABASE.BTXADDR; select count(*) from DATABASE3S.DATABASE.BTXADDR; select count(*) from DATABASE3.DATABASE.BTXSURB; select count(*) from DATABASE3S.DATABASE.BTXSUPB;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $mysqlConnection
    $mysqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $mysqlConnection.Close()
    if ($Result -gt 0) {return $True} else {return $False}
    function Execute-MySQLCommand {param( [string]$Server, #the host name of the SQL server
    [string]$DATABASE3, #the name of the database
    [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)
    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "DATABASE_CONNECT_STRING=DSN=DATABASE3;Description=DATABASE3;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE3;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $sqlConnection
    $sqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $sqlConnection.Close()
    if ($Result -gt 0) {return $TRUE} else {return $FALSE}
    cd /d/DATABASE3/code_stg
    install ../DATABASE0980453.pkg
    function Copy-File {
    #.Synopsis
    # Copies all files and folders in $source folder to $destination folder, but with .copy inserted before the extension if the file already exists
    param}($DATABASE0980453.pkg,"d/DATABASE3/code_stg")
    # create destination if it's not there ...
    #mkdir $destination -force -erroraction SilentlyContinue
    foreach($original in ls $source -recurse) {
    $result = $original.FullName.Replace($source,$destination)
    while(test-path $result -type leaf){ $result = [IO.Path]::ChangeExtension($result,"copy$([IO.Path]::GetExtension($result))") }
    if($original.PSIsContainer) {
    # mkdir $result -ErrorAction SilentlyContinue
    # } else {
    copy $original.FullName -destination $result
    While($ElementDistro -match $DATABASE4 ) {
    function Execute-MySqlcommand {param( [string]$Server, #the host of the SQL server
    [string]$DATABASE4, #the name of the database
    [System.Data.MySqlclient.MySqlcommand]$Command) #the command to execute (name of stored command)
    $mysqlConnection = new-object System.Data.MySqlclient.MySqlConnection
    $MySqlConnection.ConnectionString = "DROP_VIEW DATABASE.BTXADDR;DROP_VIEW DATABASE.BTXSUPB;CREATE_VIEW DATABASE.BTXADDR FOR DATABASE4.DATABASE42.BTXADDR;CREATE_VIEW DATABASE.BTXSUPB FOR DATABASE4.DATABASE4S3.BTXSUPB"
    $MySqlConnection.ConnectionString = "TRUNCATE TABLE DATABASE4.DATABASE4S2.BTXADDR;TRUNCATE TABLE DATABASE4.DATABASE4S3.BTXSUPB; INSERT INTO DATABASE4.DATABASE4S3.BTXSUPB SELECT * FROM DATABASE4.DATABASE4S2.BTXSUPB; select count(*) from DATABASE4.DATABASE.BTXADDR; select count(*) from DATABASE4S.DATABASE.BTXADDR; select count(*) from DATABASE4.DATABASE.BTXSURB; select count(*) from DATABASE4S.DATABASE.BTXSUPB;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $mysqlConnection
    $mysqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $mysqlConnection.Close()
    if ($Result -gt 0) {return $True} else {return $False}
    function Execute-MySQLCommand {param( [string]$Server, #the host name of the SQL server
    [string]$DATABASE4, #the name of the database
    [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)
    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "DATABASE_CONNECT_STRING=DSN=DATABASE4;Description=DATABASE4;Trusted_Connection=Yes;WSID=Server;DATABASE=TF90PVS;"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $sqlConnection
    $sqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $sqlConnection.Close()
    if ($Result -gt 0) {return $TRUE} else {return $FALSE}
    function Copy-File {
    #.Synopsis
    # Copies all files and folders in $source folder to $destination folder, but with .copy inserted before the extension if the file already exists
    param}($DATABASE0980453.pkg,,"d/DATABASE4/code_stg")
    # create destination if it's not there ...
    #mkdir $destination -force -erroraction SilentlyContinue
    foreach($original in ls $source -recurse) {
    $result = $original.FullName.Replace($source,$destination)
    while(test-path $result -type leaf){ $result = [IO.Path]::ChangeExtension($result,"copy$([IO.Path]::GetExtension($result))") }
    if($original.PSIsContainer) {
    # mkdir $result -ErrorAction SilentlyContinue
    # } else {
    copy $original.FullName -destination $result
    cd /d/DATABASE4/code_st
    install ../DATABASE0980453.pkg
    While($ElementDistro -match $ALL ){
    function Execute-MySQLCommand {param( [string]$Server, #the host name of the SQL server
    [string]$DATABASE1,$DATABASE2,$DATABASE3,$DATABASE4, #the name of the database
    [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure)
    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "(DATABASE_CONNECT_STRING=DSN=DATABASE1;Description=DATABASE1;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE1;DATASET=DEFAULT;),(DATABASE_CONNECT_STRING=DSN=DATABASE2; Description=DATABASE2; Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE2;),(DATABASE_CONNECT_STRING=DSN=DATABASE3;Description=DATABASE3;Trusted_Connection=Yes;WSID=Server;DATABASE=DATABASE3;),(DATABASE_CONNECT_STRING=DSN=DATABASE4;Description=DATABASE4;Trusted_Connection=Yes;WSID=Server;DATABASE=TF90PVS;)"
    $Command.CommandType = 1 # 1 is the 'Text' command type
    $Command.Connection = $sqlConnection
    $sqlConnection.Open()
    $Result = $Command.ExecuteNonQuery()
    $sqlConnection.Close()
    if ($Result -gt 0) {return $TRUE} else {return $FALSE}
    install ../DATABASE0980453.pkg
    While($ProductionDistro -match $Cyc) {
    write-host "Sets up location you want to run staging"
    $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"
    While($ElementDistro -notmatch "(DATABASE1|DATABASE2|DATABASE3|DATABASE4|ALL)") {
    write-host "you have enterd an error" -ForgroundColor Red
    write-host "You must type DATABASE1 or DATABASE2 or DATABASE3 or DATABASE4 or ALL"
    write-host "you typed $ElementDistro"
    write-host "set location you want to run staging"
    $ElementDistro = Read-Host -Prompt "Which Element do you want to run? (DATABASE1/DATABASE2/DATABASE3/DATABASE4/ALL)"

    OK, so you've got a reasonable input loop early on:
    write-host "This script sets up DATABASE Staging"
    $ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(TC/MonsterLock/Cyc)"
    While($ProductionDistro -notmatch "^(TC|MonsterLock|Cyc)$"){
    write-host "You have entered an error" -ForegroundColor Red
    write-host "You must type TC or MonsterLock or Cyc"
    write-host "you typed $ProductionDistro"
    write-host "This script sets up DATABASE Staging"
    $ProductionDistro = Read-Host -Prompt "Which production do you `enter code here`want to run?(TC/MonsterLock/Cyc)"
    I've only added two things to that code:  a ^ and $ at the beginning and end of your regex pattern.  As originally written, it would have successfully matched any string containing TC, MonsterLock or Cyc (such as "bogusTCwhatever", etc).
    Now, instead of a bunch of extra While loops based on $ProductionDistro, what you need is some conditionals (either a Switch statement, or some If/ElseIf).  For example:
    switch ($ProductionDistro)
    'TC'
    # Do TC Stuff
    break
    'MonsterLock'
    # Do MonsterLock Stuff
    break
    'Cyc'
    # Do Cyc stuff
    break

  • How to use while loops to implement a simple climate control.

    Hi,
    I am currently a 4’th year computer systems engineering student in South Africa doing a primitive climate control project in LabVIEW 8.0. Although my knowledge and skill level of LabVIEW is far from that of an expert, I really enjoy working with it. The project consists of a motor driving some fan blades, a resistor heater and an analog temperature sensor. The basic functionality entails that a user specifies a desired temperature and then the program will heat if the current temperature is lower than desired or cool if the current temperature is above the desired temperature.
    What I want to add is an acceptable temperature difference so that the fan and heater do not switch constantly as the threshold temperature is reached. Rather leave the current temperature to linger between the maximum (current + acceptable difference) or minimum (current – acceptable difference) allowed temperature before heating or cooling it to the desired temperature once again.
    I have attached 2 VI’s:
    Final Assignment: I tried to achieve the sensible climate control by making use of a formula node. As soon as I substituted the if statements in the formula node with while statements, the VI did not respond. It did not give any errors, it just didn’t respond.
    Final Assignment2: I tried the same but by making use of while loop structures. The while where my Input DAQ is works fine, but none of the other while loops work.
    Please advise me on possible solutions for my problem/project.
    Thank you in advance.
    D. Weppenaar
    Attachments:
    Final Assignment1.vi ‏254 KB
    Final Assignment21.vi ‏256 KB

    1. Your VI does not respond because your formula node is trapped in an infinite loop and cannot exit if you're out of the deadband. Replace the words "while" with "if" (or similar) and you might be getting somewhere. Sorry, I don't have DAQ installed, but what determines the loop rate?
    2. You have a dataflow issue. Only the inner loop on the left will run. All other loops must wait because they depend on data from the first loop. data is only available at an output tunnel of a loop once the loop finishes and a loop cannot start until all input tunnels contain data. Also the first loop can never stop, because the stop button is outside the loop and will never get read once the inner loop starts. The stop button needs to be in the innermost loop.
    Most likely, all code segments should run synchronized, so delete all the inner loops. They serve no purpose. All yon need is the big outer loop as in the first code.
    There are many ways to directly observe what is going on. For example you could run the VI in execution highlighting mode while watching the diagram.
    Clearly, you need to become more familiar with LabVIEW basics. Maybe do a tutorial? Right now you might think that dataflow is a hindrance while in fact it is one of the most powerful advantages of dataflow programming. You simply need to be familiar with its logic.
    LabVIEW Champion . Do more with less code and in less time .

  • Capturing of time taken by a while loop in bpm

    Hi ,
    I have a busniess process ,and my receive step is defined in a while loop.
    so it starts with a while loop.
    I want to keep a condition on the while loop that it should receive the messages only for a period of 1 hour ,and if it exceeds this period it should end up the process triggeringa mail.
    I mean to say if there are 12 records to be processed through the while loop ...and if I receive only 11 records ..it will be waiting for that final record in an infinite loop ..so I dont want that ...instead if the total no of records are reached then it should move forward ..If it is waiting for the missing records for an hour ..I should stop the process and trigger a mail to the queue monitor saying that record is missing...I have finished the process without this processing time condition successfully..
    I am new to XI and I dont have any idea on how to capture this processing time of while loop.
    can some one please help me out in this issue...
    Thank you in advance...

    Hi Latika,
    Yeah I understand we can go with fork but why I am going with this is ,I have already designed a Payload dependent loop ,by using while loop.so it makes my job simple ...
    Now I am converting it to time dependent loop,so only the final question I have is...In the time dependent loop documentation ..they have taken it as infinite loop and only kept the time limit in the deadline branch...so when the deadline reaches they trigger something.
    If you go to the documentation of time dependent loop(http://help.sap.com/saphelp_erp2005vp/helpdata/en/08/16163ff8519a06e10000000a114084/content.htm) ..they took the infinite loop...in this loop if I mention the counter ..and if this record count triggers before the time limit...it should come out of the block...would it work this way ?
    Thanks a lot...

  • While loop in a for loop,Is it possible?

    Is It possible to call a while loop a particular number of time's using a for loop.
    for example :
    for(.....){
    while(true)
    Is this technically possible?
    Thanks,

    Hans9777 wrote:
    Based on the code you wrote , the program will enter the for loop and then the while loop . It will never exit the while loop as while(true) means loop infinite times. normally while do-while and for loop can be immplemted for the same function therefore they are rarely used together.Obviously his code only showed the loop structures themselves with no loop bodies. Supposedly there may be a 'break' in the while loop somewhere, so it is not necessarily an infinite loop.
    And your remark about them rarely being used together is nonsense. Loops within loops are written for legitimate logic purposes all the time, regardless of what kind of loops they are.

  • Time Measurement in a While-Loop

    Greetings gentleman;
    I am a little bit new at Labview, and though i searched for an answer without posting, i was not able to find one.
    So here is my question, i would like to know how can i measure time of a loop sequence, in other words, how much time does my VI take to execute the whole main loop ?.
    A little explanation, the attached VI tries to be a Markov Chain, it takes some values in the first case structure depending of the previus loop, then, if the values are correct, it goes to the next step and so on. It is quite simple, yet, my issue lies with the time measurement. Since this is a probability "distribution" it could take infinite time to execute one single loop if it does not meet the requierements, but is programmed to meet them so an average timing should work.
    So, if you look at the While loop, the big one, that i would like to measure how much time does it take to do one round.
    Thanks for the help, i would be glad to read some ideas on how to measure that.
    Kind regards,
    Stgo.
    Solved!
    Go to Solution.
    Attachments:
    Markov Chain.vi ‏30 KB

    You can find a few examples in the NI Example Finder by searching for 'speed test' or 'benchmark'.
    Essentially, you create a flat sequence structure inside your while loop. In the first frame, you measure the current tick count. In the middle frame, you run your code. In the final frame, you measure the tick count again, and subtract the first count from this. This gives you the execution time to run the code.
    You can see a community page on it here.
    There's a high resolution tick/time count VI hanging around somewhere which is excellent for benchmarking and improving efficiency, used in place of the Tick Count (ms) primitive.
    Edit - remembered where it was
    https://decibel.ni.com/content/blogs/EvanP/2010/10/04/tick-count-us--microsecond-timing-granularity-...
    CLD

  • Stop/ abort execution in case when the task inside while loop can not be completed

    I am using Count digital events example from LabVew. This VI is using DAQmx Read vi. If I press Stop button before this DAQ gets required amount of samples VI does not stop. I tried to change amount of samples on a fly with stop button but it did not work either.
    Please help.

    This is directly related to the way LV handle the data. Your question is similar to "How can I stop a For-Next loop before completion ?". The answer is : No way, except changing the loop for a while loop (ie: change the algorithm) or stop the whole vi.
    Attached is an example of stopping an infinite running loop. It uses a parallel loop, with a Stop node (see how to handle the stop button in order to reset it to false at the next vi run).
    If you only want to stop the DAQ, whithout halting everything else, the solution is trickier : you will have to run your DAQ loop in a dynamically loaded vi, then use the vi server functions to halt the vi if the run period is excessive. But that is worth another discussion...
    Give some feedback !..
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Stop_infinite_loop.vi.zip ‏9 KB

  • Making a while loop stop

    I'm trying to write to a file by using a while loop. I read from the keyboard and then enter the while loop. I print to the file and then I read from the keyboard again. My problem is when I want to exit the loop by entering nothing I can't. The loop becomes infinite. Please help!!! Here is my code!!
    inputline = keyboard.readLine();//read the keyboard
    while ( inputline != null ){
    DiskOut.println( inputline );
    DiskOut.flush();
    inputline = keyboard.readLine();//read the keyboard again
    }//end while

    At a guess, it's not returning null when you hit return, but rather the return character. Try something like
    if (inputline == "" || inputline =="\n" || inputline == "\r" || inputline == null) {break;}If that works, you can take out bits to see what it is returning.

Maybe you are looking for

  • AS2 SSL Error

    Hi Experts, Has anyone encountered this error before? SEEBURGER AS2: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? # Regards,

  • Material Ledger,Revaluation Production Cost Center ,Standard Cost

    Hi, I have a problem with  revaluation of production cost centers. Firstly,  production cost center expenses are settled via activity types onto the production order at the end of the period. However,  CKMLCP revaluate cost centers after the settleme

  • Sending 2 Different Data

    hi i wanted to send a string text (id) and a image byte from my phone to the servlet how can i do so? using doPost?

  • MAIL - crashing! Wha?

    My new(ish) iPhone's MAIL program crashes 3 or so seconds after being launched. I have a POP and a Yahoo account on it... but it goes down immediately. I was working fine for a month...and then POOF it's stopped working. Don't see any other issues wi

  • Alternate Text in a Figure Tag

    Is there a control, option, or preference that can be toggled on or off for when the alternate text in a figure tag shows when the cursor is hovering over an image in a tagged pdf? I am trying to get it so that the alternate text does NOT show when t