0

How to control a loop if you don't know how many times it has to be executed?

I must pass the first letter at the end of each word in a phrase, the phrase will be typed by the user. Also, add "hey" to the end of each word example MI car is red imey arrocey seey ojorey I managed to pass the first letter at the end of each word, but I could not control the cycle so that it only runs the number of times necessary because I do not know how many words the phrase the user will have. this is my result MI car is red imey arrocey seey ojorey hey hey hey hey hey hey

4th Apr 2020, 3:55 AM
jhon sebastian zuñiga lopez
jhon sebastian zuñiga lopez - avatar
2 Answers
+ 2
While loop can be useful when you don't know how many times your loop block needs to be executed. While (condition) { statement(s); }
4th Apr 2020, 4:03 AM
Bhavya
Bhavya - avatar
0
This is the code that I have done so far, but I can't get the loop to only run as many times as necessary https://code.sololearn.com/c43TGR5l3y8K/?ref=app I can't get the "hey" to keep repeating when the phrase is over
4th Apr 2020, 11:02 PM
jhon sebastian zuñiga lopez
jhon sebastian zuñiga lopez - avatar