0% found this document useful (0 votes)
8 views1 page

Understanding For Loops in Programming

The document explains the use of for loops in programming, which are utilized when the number of iterations is predetermined. It provides the syntax for a for loop and describes the components: initialization, condition, and update expressions. An example is given to illustrate how a for loop works, printing numbers from 1 to 9.

Uploaded by

Netra Yardoni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Understanding For Loops in Programming

The document explains the use of for loops in programming, which are utilized when the number of iterations is predetermined. It provides the syntax for a for loop and describes the components: initialization, condition, and update expressions. An example is given to illustrate how a for loop works, printing numbers from 1 to 9.

Uploaded by

Netra Yardoni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Lecture Note: 8

for loop
In a program, for loop is generally used when number of iteration are known in
advance. The body of the loop can be single statement or multiple statements. Its
syntax for writing is:
Syntax:-
36 *Under revision

for(exp1;exp2;exp3)
{
Statement;
}
Or
for(initialized counter; test counter; update counter)
{
Statement;
}
Here exp1 is an initialization expression, exp2 is test expression or condition and
exp3 is an update expression. Expression 1 is executed only once when loop
started and used to initialize the loop variables. Condition expression generally
uses relational and logical operators. And updation part executed only when after
body of the loop is executed.
Example:-
void main()
{
int i;
for(i=1;i<10;i++)
{
37 *Under revision

Printf(“ %d ”, i);
}
}
Output:-1 2 3 4 5 6 7 8 9

You might also like