Results 1 to 2 of 2
- 07-11-2008, 10:36 PM #1
Member
- Join Date
- Jul 2008
- Posts
- 6
- Rep Power
- 0
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.....
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.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
I have tried doing:
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.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);
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
- 07-12-2008, 12:24 AM #2
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
-
while loop
By Unknown1369 in forum New To JavaReplies: 5Last Post: 07-08-2008, 10:15 AM -
Increment a Variable
By rhm54 in forum New To JavaReplies: 2Last Post: 06-14-2008, 02:57 AM -
Object ArrayList - increment solution needed badly!!
By rugbyGeek in forum New To JavaReplies: 4Last Post: 03-08-2008, 12:47 AM -
How to create auto-increment
By Albert in forum JDBCReplies: 2Last Post: 07-04-2007, 05:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks