break statement in "if else" - java

Viewed 271347

I keep getting an error, if without else.

I tried else if as well

for (;;){
        System.out.println("---> Your choice: ");
        choice = input.nextInt();
        if (choice==1)
            playGame();
        if (choice==2)
            loadGame();
        if (choice==3)
            options();
        if (choice==4)
            credits();
        if (choice==5)
            System.out.println("End of Game\n Thank you for playing with us!");
            break;
        else
            System.out.println("Not a valid choice!\n Please try again...\n");=[;'mm
    }

also if you have a better idea on how to present this code please do not hesitate :)

4 Answers

Where some went there to provide alternative implementation of code the reason that the op code does not work is a missing {} pair;

    if (choice==5) {
        System.out.println("End of Game\n Thank you for playing with us!");
        break;
    } else
Related