I wrote a simple C program that counts from 0 to 20. Here's the code I have:
```c
#include
int main() {
int count = 0;
do {
printf("%dn", count);
count++;
} while (count <= 20);
return 0;
}
```
My question is, after the loop reaches 20 and ends, how do I continue executing more instructions? I'm not sure what to do next. Any guidance would be appreciated!
5 Answers
To keep your program going after counting, you’ll have to add more code after the loop! Right after the `do` while statement ends, just write any other commands you want. If you want to count further or do something else, just add that logic below the loop instead of ending with `return 0;`.
Your loop just ends when `count` hits 20, which is expected. If you want it to keep doing something, you can add more logic right after your loop. For example, just put some new statements there! If you want to prevent the console window from closing instantly, consider using `cin.get();` to wait for user input before exiting, or run the program from the command line.
If you’re looking to do other operations after counting, make sure to code those tasks after the loop. Right above `return 0;`, you might want to print another message or perform calculations! Just remember, if you want the program to pause before closing, you could add `system("pause");` or something similar to keep it open for user input.
It seems like you're missing any code after your loop. The program does continue execution after the loop; it just happens that you have nothing to do after the loop, so it reaches `return 0;` and exits. If you want to keep the program running or do something else after counting, simply add your next instructions right before `return 0;`.
When the loop is done, the next line (`return 0;`) runs, which means your program ends. If you want to add functionality after the counting, feel free to write whatever code you wish right before that `return 0;` statement! It's all about laying out your instructions in the right order.

Thanks for the tip! I didn't think about running it from command line.