Results 1 to 13 of 13
  1. #1
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Question continue outside of loop...

    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();
    		}
    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...

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default Re: continue outside of loop...

    Quote Originally Posted by J-max04 View Post
    Java Code:
    while(!Player.isDead && !Enemy.isDead);
    What is that semicolon doing there?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default 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 on
    Last edited by J-max04; 05-03-2012 at 09:46 AM.

  4. #4
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: continue outside of loop...

    fixed that, need help with a runtime error:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Last edited by J-max04; 05-03-2012 at 10:04 AM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default 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.

    ** This space for rent **

  6. #6
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: continue outside of loop...

    the while loop is in the main method
    Java Code:
    void main(String args[])

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default 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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: continue outside of loop...

    ... and public

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default 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)

  10. #10
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: continue outside of loop...

    Now whenever i input it says "Incorrect input"...

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: continue outside of loop...

    Don't sompare Strings using '==', use equals() instead.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: continue outside of loop...

    whats the syntax for that? equals(String, String)?

  13. #13
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: continue outside of loop...

    its alright, i fixed it, thx everyone

Similar Threads

  1. Interrupt loop without break or continue
    By mwr1976 in forum New To Java
    Replies: 2
    Last Post: 10-12-2011, 03:43 AM
  2. use Continue with label
    By er1c550n20 in forum New To Java
    Replies: 2
    Last Post: 04-04-2010, 01:24 PM
  3. Continue or not?
    By kliane in forum New To Java
    Replies: 3
    Last Post: 01-19-2010, 02:42 PM
  4. press any key to continue
    By dotnet007 in forum New To Java
    Replies: 3
    Last Post: 05-11-2008, 05:19 AM
  5. How to use Continue
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •