Prabhakar Reddy Bokka wrote:You can try this.
The 'flag' variable is not needed here. As soon as you set it to false the next line returns from the method so the false value will never be checked. Rob's code did exactly what you wanted. If you only wanted to exit the loop and not return from the method, you could replace the return with a break.
You could do it using a flag, but you then wouldn't need the return statement.