Differentiate between for loop and while loop?

 

Answer:

For loop

While loop

The for statement is used to iterate over a range of values or a sequence .

The while statement executes a block of code repeatedly as long as the control condition of the loop is true. 

It is called a definite loop.

It is called an indefinite loop.

Flowchart:

Flowchart of for loop - Teachoo.jpg

Flowchart:

Flowchart of while loop - Teachoo.jpg

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.