answersLogoWhite

0

What are some examples of loops in C plus plus?

Updated: 8/19/2019
User Avatar

Wiki User

10y ago

Best Answer

The following example demonstrates all 4 loop structures in C++.

#include<iostream>

int main()

{

int i;

std::cout<<"For loop...\n"<<std::endl;

for(i=0; i<10; ++i)

std::cout<<i;

std::cout<<'\n'<<std::endl;

std::cout<<"While loop...\n"<<std::endl;

i=0;

while(i<10)

std::cout<<i++;

std::cout<<'\n'<<std::endl;

std::cout<<"Do-while loop...\n"<<std::endl;

i=0;

do

{

std::cout<<i;

}while( ++i<10 );

std::cout<<'\n'<<std::endl;

std::cout<<"Goto loop...\n"<<std::endl;

i=0;

again:

std::cout<<i;

if(++i<10)

goto again;

std::cout<<'\n'<<std::endl;

}

Output:

For loop...

0123456789

While loop...

0123456789

Do-while loop...

0123456789

Goto loop...

0123456789

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are some examples of loops in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How does C plus plus endeavor to represent the loop paradigm?

Iterative loops in C/C++ are represented by for(), while() and do...while() code blocks. Recursive loops are represented by functions calling themselves.


How do you make two loops run at the same time in c plus plus?

With two threads.


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


C plus plus and java are examples of what languages?

They are not examples of languages. They arelanguages.


C programs using loops?

Loops are very important part of a C-language. If we have to run our programe multiple time then we use Loops of C.


C plus plus bit-wise operators?

Are very useful. Examples: &amp; | ^ ~


What is literal in c plus plus?

Examples: 1, -1, -2.5, 'a', "Hello", NULL


What is available in C language but not in C plus plus?

Not much. Examples, that are possible in C only: char str3[3] = "ABC"; int new;


What is label in c plus plus?

Labels are used to mark the start of a code segment. They are often used in conjunction with goto statements, allowing procedural jumps and loops to be formed.


Can all C programs are executable in C plus plus?

Some C programs can be compiled in C++, yes.


What are loops in C?

In very simple terms, Loops in any language are used to perform a task repetitively.


What is the difference between cc plus plus and c sharp?

C# is inherited from c++ with some additional features