Q:

WHILE Loop Condition Does Not Validate Input

I have a WHILEloop which checks for marks for a particular student. However, it does not loop if the value is invalid (input less than 0 and more than 100):
int marks= -1;

System.out.print("Student Marks (/100): ");
                while (((marks< 0) || (marks> 100))) {
                    try {
                        marks = Integer.parseInt(sc.nextLine());
                        break;
                    } catch (NumberFormatException nfe) { 
                        System.err.println("Error: Invalid Mark(s)");
                        System.out.print("Student Marks (/100): ");
                    }
                }

It does catches exception if characters other than numbers are entered.
But it does not loop again if value if less than 0 or more than 100.
I have tried making many changes to it but to no result.
Any help given is appreciated!

A:

You should remove the break statement, since it breaks you out of the loop regardless of what value of marks was input.

