Suppose you are writing a program that counts the number of alphanumeric characters in every sentence in a document. Would you use a for loop or a while loop to process each sentence, and why? A for loop because the program must establish maximum sentence length. A for loop to control the number of characters the program will process in each sentence. A while loop because the program cannot predict the length of a sentence. A while loop to specify the list of alphanumeric characters the program will recognize.
When you use a for loop, you generally need to know how many times you need to iterate through the loop In this case, we don’t know ahead of time how long the sentences, so we don’t know how many times the loop needs to iterate. So in this case, a while loop would be better.
Hmmm so C.) sounds like the better option " A while loop because the program cannot predict the length of a sentence."
Join our real-time social learning platform and learn together with your friends!