answersLogoWhite

0


Best Answer

#include

using std::cout;

int main()
{
int a = 0;
while (a != 11) //While a does not equal 11
{
a++; //add 1 to a
cout << a << "\n"; //print a and add newline
}
cout<<"The loop has ended";
return 0;
}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

A 'do while' loop in C++ is a way to perform a few lines of code multiple times in a row. Say you wanted to print out the line "Hello, world" ten times to the screen. To print it out just one time you would use the code

cout << "Hello, world" << endl;

Let's say you wanted to do this ten times. To do this, you need a counter to track the number of times you have done it. You can accomplish this with a 'while' loop:

int i = 0; // This is your counter

while (i < 10) {

cout << "Hello, world" << endl; // This prints out the line

i++; // aka i=i+1. This indicates that you have performed the code 1 more time

}

As another example, let's say you already had a variable called indicator, and you only wanted to execute some code when indicator was less than 3 (or when indicator was false, or whatever you want). BUT maybe you want to execute the code at least once, even if indicator starts off greater than 3. This is the situation in which you want to use a 'do while' loop.

In the first example, nothing gets printed out to the screen:

int indicator = 4;

while (indicator < 3) { // At the very beginning, indicator is NOT less than 3!

cout << "Hello, world" << endl;

indicator++;

}

In this second example, "Hello, world" gets printed ONCE:

int indicator = 4;

do {

cout << "Hello, world" << endl;

indicator++;

} while (indicator < 3);

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

There are four ways to make a loop in C or C++, three of which are standard, and one of which (the goto) is non structured, non preferred...

for (init_expression; test_expression; loop_expression) statement;

while (loop_expression) statement;

do statement; while (loop_expression);

loop: statement; if (loop_expression) goto loop;

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

There are basically 3 looping statements :

1. for loop

2. while loop

3.do while loop

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you make a c plus plus program loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a C plus plus program that displays a pyramid of Xes on the screen using a for loop?

printf ("x")


How to complete this C plus plus End Of File controlled while loop program?

Add the missing parts.


C program to print numbers 1 to n?

how do we use loops in c plus plus programing and what are basic differences between do,for and while loop


How do you display stars in c plus plus using the if else structure and a for loop and you use void main?

It depends on what program you design really


How do you make C plus plus program to draw a straight line using for loop method?

void line(int length) { for(int i=0; i&lt;length; ++i) std::cout&lt;&lt;'_'; std::cout&lt;&lt;std::endl; }


Example program arrays in turbo c plus plus?

Yes, you can use for-loop in a C program compiled by Turbo C.


What is odd loop in 'C' program?

odd loop means at least the loop execute once.


Does 'for loop' works in C plus plus?

In C++, a for loop is structured as follows: for( int index = 0; index &lt; 10; ++i ) { //do something }


Is for loop is faster than while loop in turbo c plus plus compiler?

No, why did you think so?


Example of flowchart of while loop in c plus plus?

kk


Can you program games with c plus plus?

Yes, you can program games with C++.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'