Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 4th, 2013, 01:54 PM
CJL9324 CJL9324 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 4 CJL9324 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 36 sec
Reputation Power: 0
Continue to Outer Loop Isn't Working

Hey everyone. So my homework is to run a lottery program with a winning list picked randomly that doesn't have duplicates. That's the part I'm having problems with. I'm trying to check for duplicates and re-run the assignment loop if there is a duplicate. But everything I've tried, including continuing to the outer loop which I thought should work, generally creates a permanent loop. Help would be appreciated. Code segment is below.

Code:
int [] winners = new int[5];
		int c=0;
		
		outer: while (c<5)
		{
			Die d1 = new Die(1, 10);
			int w= d1.roll();
			winners[c]=w;
			System.out.print(" "+winners[c]);
				
			for(int i=0;i<5;i++)
			{ 
				boolean dup = false;
				
				for(int z=0;z<5;z++)
				{
					if(winners[i] == winners[z])
				    {
						dup = true;
						if(dup == true)
					    {
					    	continue outer;
					    }
				    }
					
				}
			}
			
			c++;
		}

Reply With Quote
  #2  
Old March 4th, 2013, 07:05 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Quote:
creates a permanent loop

The loop control variables must change for the loop to exit. Make sure all the paths the execution takes will change the variables that control the looping, otherwise the loop will go forever.
Code:
                dup = true;
		if(dup == true)

The if test is useless, it will ALWAYS be true.

Reply With Quote
  #3  
Old March 4th, 2013, 09:34 PM
CJL9324 CJL9324 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 4 CJL9324 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 36 sec
Reputation Power: 0
It was because the loops were checking the same spot in the array twice, needed to add an & clause to not let the element holding variable be the same either.

Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Continue to Outer Loop Isn't Working

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap