top of page
  • Subham Das

Iterative Structure


If same type task is repeated by a structure till the condition is true, then it is called repetitive structure or loop.

In Python two types of loop is available :-

1. while loop

2. for loop


While loop


while loop is known as entry control loop, because, the condition of the loop. If the condition is true the loop will continue else the loop will be skipped. The while in python is started with the keyword 'while'.


For while loop a counter variable is required and which is set by suitable value according to the problem. The value of the counter variable will be incremented or decremented as per the programming logic after each and every iteration in the while loop.

Syntax of while loop:

while <condition> :

statement 1

statement 2

.

.

.

statement n

<update counter variable>


For loop


A for-loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. For-loops are typically used when the number of iterations is known before entering the loop. For-loops can be thought of as short hands for while-loops which increment and test a loop variable. In computer science, a for-loop (or simply for loop) is a control flow statement for specifying iteration, which allows code to be executed repeatedly.

Syntax of for loop:

for <variable> in range (start,end,interval) :

statement 1

statement 2

.

.

.

statement n

601 views0 comments

Recent Posts

See All
logo12.PNG
bottom of page