0% found this document useful (0 votes)
35 views12 pages

Looping: Kanak Mohnot Arora

This document discusses looping in programming. It defines a loop as a block of code that is repeatedly executed until a certain condition is reached. There are two main types of loops: entry-controlled and exit-controlled. The document focuses on the for loop, providing its syntax of an initialization expression, test expression, and update expression. It gives two examples of using a for loop to add 5 numbers and to calculate a factorial. It concludes that the for loop is useful for executing code a specific number of times.

Uploaded by

Kanak Mohnot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views12 pages

Looping: Kanak Mohnot Arora

This document discusses looping in programming. It defines a loop as a block of code that is repeatedly executed until a certain condition is reached. There are two main types of loops: entry-controlled and exit-controlled. The document focuses on the for loop, providing its syntax of an initialization expression, test expression, and update expression. It gives two examples of using a for loop to add 5 numbers and to calculate a factorial. It concludes that the for loop is useful for executing code a specific number of times.

Uploaded by

Kanak Mohnot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

LOOPING

Kanak Mohnot Arora


CONTENTS
 About Looping
 Types of Looping
 Syntax of for looping
 Example 1:- Adding 5 numbers
 Example 2:- Finding Factorial of a number
 Conclusion
 Reference
LOOPING
 Loops in programming comes into use when
we need to repeatedly execute a block of
statements. 
 In computer programming, a loop is a
sequence of instructions that is repeated
until a certain condition is reached.
  After every execution of loop body,
condition is checked, and if it is found to
be true the loop body is executed again.
When condition check comes out to be false,
the loop body will not be executed. 
TYPES OF LOOP
 Entry Controlled Loop
 Exit Controlled Loop
FOR LOOP
 A for loop is a repetition control structure
which allows us to write a loop that is
executed a specific number of times. 
 The syntax is as follows:

for (expression for initialization ; expression


for testing ; expression for updating)
{ //body }
Example 1:-
Adding 5
Numbers
int count=0, sum = 0,n;
for(int count = 0; count <5; count++)
{
Cout<<“enter the value of n”;
Cin>>n
sum += n;
}
System.out.println("Sum = " + sum);
}
}
Example 2:-
Finding Factorial
of a Number
int m=1, fact= 1, n;
for (i = 1; i <= n; ++i) {
factorial *= i; // factorial = factorial * i;
}
cout<< "Factorial of "<<n<<" = "<<factorial;
CONCLUSION
C++ provides three different loops for eliciting
repetitive behaviour.
The for loop is most useful when statements
must be executed a specific number of times.
REFRENCES
 XII class Computer Science Book by Sumita Arora
 https://www.geeksforgeeks.org/loops-in-c-and-cpp/
 https://beginnersbook.com/2017/08/cpp-for-loop/
 https://www.cprogramming.com/tutorial/lesson3.html
 https://www.google.com/search?q=images+of+start&rlz=1C1KUBR_enI
N856IN856&tbm=isch&source=iu&ictx=1&fir=PrXmsXIyOn-RSM%253A%252
C7KIvsLT1NgBA5M%252C_&vet=1&usg=AI4_-kSKp0gXY6Diy0asQPSzq9IWEQ9
hRQ&sa=X&ved=2ahUKEwjzvPLP5ZzjAhVNf30KHckOAuwQ9QEwB3oECAcQEg#im
grc=PrXmsXIyOn-RSM
://image link
 https://www.google.com/search?q=images+of+stop&rlz=1C1KUBR_enIN8
56IN856&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjc_Lfm5ZzjAhXGeisKH
QIyCJUQ_AUIECgB&biw=1366&bih=657#imgrc=jSffIFvHAsIKAM
: //image link

You might also like