loop     


  loop is used for repetition, if same set of statement is needed to be repeated again and again in our program, instead of writing it many times, we can use loops. Now, we will write the program or set of statements, only once, and we will run the loop. We want program to be repeated, it is called iteration.       




Elements of loop:-



1.  initialization 

2.  condition

3   .updation 

4.    body of loop 




2. condition  :- 


Loop runs tell condition is true,  and stops when it becomes false. So, how many time program repeats depend on how many times, the condition is true.  And after saying, repetation, it also has to be  false. To stop the loop.


1.Initialization :-  


The variable, which is used  for giving condition that must be initialize by sum value so that condition could become true because it's necessary to start and run the loop .


3.Updation:- 


The variable, which is used for giving condition that value must be changed so that after desert repetation, the condition could becomes false to stop the rule. 


4.body of loop:-The program that's needs to be  repeated. Using a loop is called  Body of loop.




Syntax: 



            i=1 ; Initialization
            Loop(i <=500) condition
            {
             Cout<<"good morning "; body of loop
             i++;  updation (increment / decrement) 
             }
 


We  can contract the loop by any one of the following three way.


A. While

B. Do While

C. For




i)   While loop:-  
                          syntax:-


                                 initialization                                                                                                                                                    {
                                while  (condition)
                                 body of loop
                                 updation;
                                 }




Example 1 :-  write a program to display Good  morning 10 Times
    


#include <iostream.h>
# include <conio.h>
 void main()
{
clrscr() ;
Int   i ;
i=1;    πŸ‘‰ initialization 
While (i<=10)πŸ‘‰condition 
{
Cout<<"Good morning"; πŸ‘‰body of  loop 
i++;  πŸ‘‰ updation 
}
Getch();
}




Example 2:-   Write a program to display Hii everyone coding master  in c++ by experts twenty times. 



#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=1
While(i<=20)πŸ‘‰ condition 
{
Cout<<"coding master in c++ by experts ";
i++;
}
Getch() ;
}

Example 3:-   Write a program to display 1 to 10 numbers.

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=1
While(i<=10)πŸ‘‰ condition 
{
Cout<<i<<endl;
i++;
}
getch() ;
}

Example 4 :write a program to display 8 to 15??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=8;
While(i<=15)πŸ‘‰ condition 
{
Cout<<i<<endl;
i++;
}
getch() ;
}


Example 5 : Write a program to display 5,4,3,2,1 ??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=5;
While(i>=1)πŸ‘‰ condition 
{
Cout<<i;
i--;
}
getch() ;
}

Example 6: Write a program to display 2,4,6,8,10??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=2;
While(i<=10)πŸ‘‰ condition 
{
Cout<<i;
i+=2;
}
getch() ;
}

Example 7: Write a program to display 1 to 100??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=1;
While(i<=100)πŸ‘‰ condition 
{
Cout<<i;
i++;
}
getch() ;
}

Example 8: Write a program to display 5 to 20??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=5;
While(i<=20)πŸ‘‰ condition 
{
Cout<<i;
i++;
}
getch() ;
}


Example 9: Write a program to display 1,3,5,7 to 101??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=1;
While(i<=101)πŸ‘‰ condition 
{
Cout<<i;
i+=2;
}
getch() ;
}

Example 10: Write a program to display 5,10,15 to 500??

#include <iostream.h>
#include <conio.h>
void main() 
{
 Clrscr();
int  i;    
i=5;
While(i<=500)πŸ‘‰ condition 
{
Cout<<i;
i+=5;
}
getch() ;
}

πŸ‘‰  IF you want to know how to display any string or anything in C++ then   CLICK HERE
 
       πŸ‘‰ IF you want to know How to solve Complex type of mathematical Problem in C++ 

               Programming  CLICK HERE

πŸ‘‰ IF you want to know How to calculate percentage  in C++ Programming  CLICK HERE

πŸ‘‰ IF you want to know How to use mathematical  operator in c++     CLICK HERE 

πŸ‘‰  what is shortend operators and how to use it in program  CLICK HERE
what


Our website: 


  πŸ˜‡ https://codemasternisha.blogspot.com/πŸ˜‡



if you face any any problem or any issue about our website then fill the contact us page and write your issues in it ...

πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡



                      KEEP SUPPORTING πŸ‘Œ !!  KEEP LEARNING πŸ“š !!



                                                                    πŸ˜‡πŸ˜‡πŸ˜‡πŸ˜‡πŸ˜‡πŸ˜‡πŸ˜‡