C Program to demonstrate looping without loops
Ask the user to enter an int number. If he enters, 5, your program should print five stars. If he enters 2, your program should print 2 stars. Do not use any loops.
This program is a real candidate for a for loop. A statement label has been used only for demonstration purposes.
int main() { cout << "How many stars?: "; int i; cin >> i; int counter = 0; lblX: cout << "* "; counter++; if (counter < i) { goto lblX; } return 0; }
My C/C++ Videos on Youtube
Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.
This Blog Post/Article "C Program to demonstrate looping without loops" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2020-02-07. Published on: 2016-03-18