C Program to demonstrate looping without loops

This program demonstrates how to write a loop without any of the loop constructs. Of course, many programmers would call it a bad programming practice. Nevertheless, it is a nice program that can help us develop skills by writing a program differently.

Last Reviewed and Updated on February 7, 2020
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

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.



Creative Commons License
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