Results 1 to 13 of 13
Thread: continue outside of loop...
- 05-03-2012, 09:23 AM #1
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
continue outside of loop...
Im having trouble with this, it complains there is a continue statement outside of a loop. the 2 there are the only ones in my code... plz help...Java Code:while(!Player.isDead && !Enemy.isDead); { System.out.println("Your current weapon is a " + Player.heldItem.Name); System.out.println("Choose an action:"); System.out.println("A. Attack"); System.out.println("B. Block"); System.out.println("C. Choose Weapon"); System.out.println("D. Evade"); Player.startBattle(); Enemy.startBattle(); String choice = input.readLine(); if(choice == "a") { Player.isAttacking = true; Player.Attack(); Player.isIdle = false; } else if(choice == "b") { Player.isBlocking = true; Player.isIdle = true; } else if(choice == "d") { Player.isEvading = true; Player.Evaded = (carl.nextInt(4) != 0); Player.isIdle = true; } else if(choice == "c") { System.out.println("Choose a Weapon"); System.out.println("A. Sword"); System.out.println("B. Club"); System.out.println("C. Staff"); String choice2 = input.readLine(); if(choice2 == "a") { Player.heldItem = BaseWeapon.Sword; } else if(choice2 == "b") { Player.heldItem = BaseWeapon.Club; } else if(choice2 == "c") { Player.heldItem = BaseWeapon.Staff; } else { System.out.println("Incorrect input"); } continue; } else { System.out.println("Incorrect input"); continue; } Enemy.whatToDo(); Player.endOfRound(); Enemy.endOfRound(); }
- 05-03-2012, 09:31 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
- 05-03-2012, 09:33 AM #3
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
oops... thanks heaps man!
EDIT: now is says 'unreported exception java.io.IOException; must be caught or declared to be thrown' on line 25 and line 49, the lines i declare the strings onLast edited by J-max04; 05-03-2012 at 09:46 AM.
- 05-03-2012, 09:58 AM #4
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
fixed that, need help with a runtime error:
Exception in thread "main" java.lang.NoSuchMethodError: mainLast edited by J-max04; 05-03-2012 at 10:04 AM.
- 05-03-2012, 10:39 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: continue outside of loop...
You need a main() method in the class you are attempting to execute.
Please do not ask for code as refusal often offends.
- 05-03-2012, 10:41 AM #6
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
the while loop is in the main method
Java Code:void main(String args[])
- 05-03-2012, 11:07 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Re: continue outside of loop...
Have you read a tutorials on the basics of Java? You must've missed the fact that the main( ... ) method has to be static.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-03-2012, 11:33 AM #8
Re: continue outside of loop...
... and public
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-03-2012, 12:05 PM #9
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
I KNOW THE BASICS OF JAVA! i had it static... and public before, and in my attempts to fix it i changed it to what it is!
EDIT; heres some irony, when i change it back it suddenly works!(i must have a messed up IDE)
- 05-03-2012, 01:11 PM #10
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
Now whenever i input it says "Incorrect input"...
- 05-03-2012, 01:15 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: continue outside of loop...
Don't sompare Strings using '==', use equals() instead.
Please do not ask for code as refusal often offends.
- 05-04-2012, 12:58 AM #12
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Re: continue outside of loop...
whats the syntax for that? equals(String, String)?
- 05-04-2012, 01:48 AM #13
Member
- Join Date
- May 2012
- Posts
- 17
- Rep Power
- 0
Similar Threads
-
Interrupt loop without break or continue
By mwr1976 in forum New To JavaReplies: 2Last Post: 10-12-2011, 03:43 AM -
use Continue with label
By er1c550n20 in forum New To JavaReplies: 2Last Post: 04-04-2010, 01:24 PM -
Continue or not?
By kliane in forum New To JavaReplies: 3Last Post: 01-19-2010, 02:42 PM -
press any key to continue
By dotnet007 in forum New To JavaReplies: 3Last Post: 05-11-2008, 05:19 AM -
How to use Continue
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks