In C++ programming using the continue keyword in For Loop control flow statement causes the loop to jump to the next iteration of the loop immediately.
#include<iostream.h>
#include<conio.h>
void main()
{
for(int a = 0; a <= 10; a++) //loop looping from 0 to 10.
{
if(a == 5) //if 'a' value Equal to 5 then
{
continue; //continue it mean Skip 5.
}
cout<<a<<endl;
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
for(int a = 0; a <= 10; a++) //loop looping from 0 to 10.
{
for(int b = 0; b <= a; b++) //loop looping from 0 to 'a' value.
{
cout<<"* ";
}
cout<<"\n"; //used for New Line, U also use 'endl'.
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdlib.h> //including Library for Random.
void main()
{
cout<<"Ten random numbers in [1, 10]"<<endl;
for(int i = 1; i <= 10; i++) //loop looping from 1 to 10.
{ //random Number from 1 to 10 and assigning to 'n'.
int n = rand() % 10 + 1;
cout<<n<<endl; //and printing.
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdlib.h> //including library for Random.
void main()
{
cout<<"Ten random numbers in [1, 10]"<<endl;
for(int i = 1; i <= 10; i++) //loop looping from 1 to 10.
{ //random Number from 1 to 10 and assigning to 'n'.
int num = random(5); //Random from 0 to 5 and assigning
cout<<num<<endl; //to 'num' and printing.
}
getch();
}