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
Iterative loops in C/C++ are represented by for(), while() and do...while() code blocks. Recursive loops are represented by functions calling themselves.
With two threads.
how do we use loops in c plus plus programing and what are basic differences between do,for and while loop
They are not examples of languages. They arelanguages.
Loops are very important part of a C-language. If we have to run our programe multiple time then we use Loops of C.
Are very useful. Examples: & | ^ ~
Examples: 1, -1, -2.5, 'a', "Hello", NULL
Not much. Examples, that are possible in C only: char str3[3] = "ABC"; int new;
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.
Some C programs can be compiled in C++, yes.
In very simple terms, Loops in any language are used to perform a task repetitively.
C# is inherited from c++ with some additional features