• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

unreachable code  RSS feed

 
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hell guys! This is my first post in this forum.The following code on compilation shows  :
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unreachable code
             at A.main(A.java:60)

Can anyone help me out what is the problem?
 
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't mind me asking, but where do all the nextInt's come from ?
Without any context of what you're trying to do it's really gonna be hard to help.
Also why do you start an infinite loop, just in the hope of breaking out of it?
You also should have a look at The Java Naming Conventions
 
Shubham Rai
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inputs will come form my machine. Sir,if you think i write something terrible in my code please help me out as i am new to programming.
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
inputs normally do come from your machine, but at no point you ask the user to put something in
 
Shubham Rai
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually the above code is for a  deciding a game winner.
Where , t=no of test cases
           N=sequence of integers
           a=no selected by Bob
           b=no selected by Alice
Game will start from Bob and then Alice, alternate turns will occur in which both have to remove multiples of  no selected by them one by one . if  one is  not able to remove  multiple of their selected no the other will win.
 
Sheriff
Posts: 21555
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The outer loop of this pair is an infinite loop. It can only end by using a break, return or throw statement. You do have some break statements, but these are all located inside the inner loop. As a result, these break out of the inner loop. That means the outer loop will still continue forever.

If you want to break out of the outer loop using a break statement in the inner loop, you need to use a labeled break.
 
Saloon Keeper
Posts: 2268
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shubham Rai wrote:The following code on compilation shows  :
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unreachable code
             at A.main(A.java:60)


The compiler is complaining because for(;;) is an infinite loop and the code execution can not progress past it.

 
Shubham Rai
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You ! you solve my problem .I found my mistake and problem resolved.
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:
Also why do you start an infinite loop, just in the HOPE of breaking out of it?


I actually already maded that remark
 
Shubham Rai
Greenhorn
Posts: 23
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well  after one player's turn i have to start iterating the arrayList again from 0 index to check whether any multiple of no selected by the current player is present or not in list. and so on this process will repeat as many times, until winner will not be decided .
To overcome this problem i think let's use the infinite loop and when winner will be decided ,loop will be broke by break.
 
Daniel Demesmaecker
Master Rancher
Posts: 915
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an while or do whileloop using a boolean would be cleaner...
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!