Friday, April 13, 2012

Validation of input

Example: If you want the user to input the age of a person, you do not want to accept any letter characters or negative numbers or numbers larger than 100.

You can use a simple repeat loop to validate input:
It is necessary to set the initial value of the variable used in the condition of the loop,before the loop, otherwise the loop may not execute at all.

The code after the loop will complete the program with a valid value for age.

No comments:

Post a Comment