You are on page 1of 7

INTRODUCTION

CONTENTS

 Use of for loop

 Syntax of for loop

 Flowchart

 example
 When we use for loop
The is used to iterate the statement or a part of the
program several times.

 For example ,if we want to print a statement 1000 times.


Then instead of writing the print statement 1000 times,we
can use a loop.
Syntax of for loop
For (initialization;condition;update){
// body of loop
}
Here,initiazation –initializes variables and is executed only once

condition – if true, the body of for loop is executed


if false, the for loop is terminated.
 Example :- 1
How Program Works
// Printing Numbers From 1 to 5 Iteration Variable i<=5 Action
#include<iostream.h> 1st i=1 true 1 is printed. i is increased to 2.
using namespace std;

int main() { 2nd i=2 true 2 is printed. i is increased to 3.


for (int i =1 ; i<=5 ;++i){
cout<< i <<“ ” 3rd I=3 true 3 is printed. I is increased to 4.
}

i=4 true 4 is printed. i is increased to 5


return 0; 4th
}
5th I=5 true 5 is printed. i is increased to 6
Output: 1 2 3 4 5 6th i=6 false the loop is terminated.
Thank You.

You might also like