Why FOR Loop was Chosen and Input Validation
VerifiedAdded on 2019/09/13
|2
|331
|203
Report
AI Summary
This assignment discusses the use of a FOR loop instead of a WHILE loop in the main part of the program. The reason for this choice is that the number of iterations is known beforehand, as it is decided by the value of the `HowFar` variable. This ensures that the loop will execute exactly `HowFar` times. In contrast, a WHILE loop would continue executing until a certain condition is met, which could lead to unexpected termination if not handled properly. The assignment also touches on the topic of validating user input to prevent the program from terminating abruptly. An example of an invalid input and a method (`validateInput`) are provided to demonstrate this.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
1 out of 2