Narendira Sarma wrote:
Peter Granstrom wrote:
Hi i liked your answer,
but i think in the if() i would try to decide if boolean to true or false before
because then you dont have to make changes afterwards and can decide
before if its right or wrong and probably get a better structure in your code
Hi Peter,
I couldn't understand what you were trying to say. I am a rookie programmer myself. That being said, I showed him how "I" would have handled the situation.
But I am eager to learn. Could you please tell me more clearly?
Thanks
-Naren
Narendira Sarma wrote:In your code posted above, you are displaying the Error message after each combination is checked from the text file.
Instead of showing the Error message in the else part, you can have a boolean variable assigned to false. If a match is found assign the boolean as true.
After the while loop finishes, check for the boolean and if it is false, display the Error message. This way you will display the error message only once.
Hope I am clear. I will write something like below.