Results 1 to 2 of 2
  1. #1
    dcnorman07 is offline Member
    Join Date
    Jul 2008
    Posts
    6
    Rep Power
    0

    Default Restart a For loop and increment an Int value

    Hi all,

    I am needing some serious help! I will try my best to explain what is going on here and what I am trying to accomplish.

    I have a script that I am needing to run against a website. The values for input on the screen are all coming from a datapool. Some of the information passed to the website is supposed to make the 'run' fail on purpose, some are not. I start off by using the for loop to get the correct line from the datapool. Here is some example of the code I am using.....

    Java Code:
    for (int i = 1; i <= 32666; i++)
    	    {
    	    Object[] objectdataToPass = new Object[1];
    	    String iteration = String.valueOf(i);
    	    objectdataToPass[0] = iteration;
    
    	    // Get correct datapool line for this iteration
    	    boolean found = false;
    	    while (!found)
    	    {
    	        // Searches through datapool until it finds the correct iteration
    	        if (dpString("Quote").equals(iteration))
    	            found = true;
    	        if (!found)
    	            dpNext();
    	    }
    // more code is entered....blah blah blah
    which works perfectly! Then as it is going through the site, I may come across an error message. When I do so, I want to jump out of the For loop and start back from the beginning, only this time I need the 'int i' to be incremented by 1 so it will grab the next line in the datapool and restart from the top.

    I have tried doing:

    Java Code:
    		boolean login = false;
    		do{
    for (int i = 1; i <= 32666; i++)
    	    {
    	    Object[] objectdataToPass = new Object[1];
    	    String iteration = String.valueOf(i);
    	    objectdataToPass[0] = iteration;
    
    	    // Get correct datapool line for this iteration
    	    boolean found = false;
    	    while (!found)
    	    {
    	        // Searches through datapool until it finds the correct iteration
    	        if (dpString("Quote").equals(iteration))
    	            found = true;
    	        if (!found)
    	            dpNext();
    	    }
    
    
    String Error = (String)table_errorSummary_errorSummar().getProperty(".text");
    			if (Error.startsWith("Error")) 
    			{
    			    System.out.println("There was an error logging in. Continuing to next iteration.");
    			    login = true;
    			}
    // more code is entered...blah blah blah
    } while (!login);
    Hoping that when the boolean value of 'login' was changed to true because there was an error message, it would jump out of the For loop and start over, but that obviously isn't the case, or I wouldn't be asking for help.

    The boolean value of 'login' does get changed to true when an error message is present, but it does not jump out of the loop and start over, it just continues on like nothing ever happened. I have no idea why this is not working. Any help would be greatly appreciated.

    Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Add a LOT more println() statements to your code to show how the code is executing and what the values of the variables are. You should be able to see what is happening then.

    The for loop (inside the do{}while) isn't affected by the value of login. Look at break instruction usage.

    Hard to see the matching {} with your indenting. One way to make it easy to see the matching {} is by commenting the ending one: } // end for(i) or } // end while(!logon)

Similar Threads

  1. while loop
    By Unknown1369 in forum New To Java
    Replies: 5
    Last Post: 07-08-2008, 11:15 AM
  2. Increment a Variable
    By rhm54 in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 03:57 AM
  3. Object ArrayList - increment solution needed badly!!
    By rugbyGeek in forum New To Java
    Replies: 4
    Last Post: 03-08-2008, 01:47 AM
  4. How to create auto-increment
    By Albert in forum JDBC
    Replies: 2
    Last Post: 07-04-2007, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •