Because without the while loop you only read one character (g) which isn't a vowel. So the count remains 0. With the while loop, you read the whole word, and find two vowels (the o's), so the count is incremented to 2.
Because without the while loop you only read one character (g) which isn't a vowel. So the count remains 0. With the while loop, you read the whole word, and find two vowels (the o's), so the count is incremented to 2.
Thank you very much.
Would you please explain more detailedly? Y with the while loop, it will read the whole word. and without the loop, it will only read the first character?
Without the loop: there is one read, and the program continues normally. Since there is no loop, none of that code is every repeated.
With the loop: there is a read at the start of the loop; you input 'g', which is good data, so it enters the loop. It's not a vowel, so it doesn't increment the counter. It reaches the end of the loop, and checks the condition again. This entails reading another character. It reads a 'o', which is good data, so it enters the loop. It's a vowel, so the counter is incremented. It reaches the end of the loop, and checks the condition again. This entails reading another character. It reads a 'o', which is good data, so it enters the loop. It's a vowel, so the counter is incremented. It reaches the end of the loop, and checks the condition again. This entails reading another character. It reads a 'd', which is good data, so it enters the loop. It's not a vowel, so the counter isn't incremented. You then input Ctrl+z, which is EOF if I recall correctly, so the loop terminates.