Results 1 to 4 of 4
Thread: How do you properly use break?
- 03-08-2011, 02:28 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
How do you properly use break?
Hello Again!
I'm getting the error, "break outside switch or loop," with the following code:
Java Code://User Input and Validation Method (Input (from user): decimal; Return: decimal): public static int getInput(int decimal) { Scanner input = new Scanner(System.in); //While Loop to test for valid input: while (decimal > 0); { //decimal = User Input: System.out.println("Please input a number from 1 to 65535, or a negative number to quit:"); decimal = input.nextInt(); //If Statement to Check Validity; Return only on Valid decimal, or Termnimate decimal: if (decimal > 65535) { System.out.println("That number is too large!"); } else if (decimal <= 65535) { [COLOR="Red"] break;[/COLOR] // break to return valid input or Termination Request } } return decimal; }
It seems to me, though, that the break is inside a loop! Any thoughts?
Thank you.
- 03-08-2011, 02:39 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You have misplaced something. I am being intentionally vague to make you think.
- 03-08-2011, 02:55 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
Aha! I spotted that unneeded semicolon.
I'm still at the point where I can't tell if I'm misusing keywords or if I'm making some sort of other syntax error. If the compiler doesn't spot it (as was the case with the extra semicolon) I get a little overwhelmed.
Thank you for letting me know it was something I had done wrong, and pushing me to look harder.
- 03-08-2011, 02:58 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
break statement
By AbdulAziz Bader in forum New To JavaReplies: 17Last Post: 06-02-2010, 03:42 PM -
Break Recursion
By AMaineJR in forum New To JavaReplies: 6Last Post: 05-14-2010, 04:47 AM -
Break to certain class
By Arez in forum New To JavaReplies: 4Last Post: 10-20-2008, 04:13 AM -
How to use Break with a label
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM -
How to use Break
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks