Results 1 to 4 of 4
Thread: Loop and retry.
- 02-16-2011, 09:51 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
Loop and retry.
Hey Guys/Gals,
I'm attempting to build a loop that adds one to a counter each time a user answers a question correctly. Then once the set number of questions have been asked, the user is prompted to see if they want to go again.
I've got this all working correctly so far, here's where the problem comes in. To begin I needed to initialize the count variable in the first method count = 0;
When the user says yes to go again, I call the method with the loop, which sets the count to zero and away we go.
I guess my main problem is how can I make the counter outside of the loop?
Just as an added bonus problem, I'd also like to keep track of how many questions have been asked, but I assume that the same principal for putting the counter outside the loop would help with this also.
Thanks,
KaW
-
declare your counter variable(s) before the loop. Then increment them when necessary in the loop.
- 02-16-2011, 10:08 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 7
- Rep Power
- 0
OK,
so what you're saying is:
Main Method
int count = 0
Loop Method
++count
Retry Method
yes/no
Loop()
Display Method
System.out.println(count);
Here's where I'm fuzzy. As long as I don't declare a local variable named count in any other method, then they will all change the value of the count variable in Main? (When I increment them that is?)
- 02-16-2011, 10:44 PM #4
Similar Threads
-
JTextField loop 2x for-loop WEIRD!
By Streetproject in forum AWT / SwingReplies: 2Last Post: 02-16-2011, 05:46 PM -
[Q] Loop issue (while loop)
By iriscience in forum New To JavaReplies: 9Last Post: 01-31-2011, 04:21 PM -
Retry constructing a thread/ terminate thread
By coyote1982 in forum New To JavaReplies: 6Last Post: 09-17-2009, 09:38 AM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 08:46 PM -
For Sale - Sun Java Certification Voucher with Free Retry
By johnenom in forum Java CertificationReplies: 0Last Post: 02-12-2009, 10:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks