|
Reprompting
A Programming Pattern |
|
Prof. David Bernstein |
| Computer Science Department |
| bernstdh@jmu.edu |
if statement to validate and re-prompt
Prompt the user to enter their age;
Read the user's response;
Assign the response to the variable named age;
if (age is negative) {
Prompt the user to enter their age;
Read the user's response;
Assign the response to the variable named age;
}
Use the variable named age;
while and do loopsdo loop. In the body of the loop:
while loop when the response is invalid.
In the body of the loop: