Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
272 views
in Review of C++ Programming by (30.5k points)
closed by

Explain different loops in detail?

1 Answer

+1 vote
by (30.4k points)
selected by
 
Best answer

1. For loop: 

The syntax of for loop is 

for(initialization; checking ; update loop variable) 

{

Body of loop; 

}

First part, initialization is executed once, then checking is carried out if it is true the body of the for loop is executed. Then loop variable is updated and again checking is carried out this process continues until the checking becomes false. It is an entry controlled loop.

Eg. for(i=1 ,j=1 ;i<=10;i++,j++) 

cout<<i<<"*"<<j<<"="<<i*j;

2. While loop: 

It is also an entry controlled loop 

The syntax is given below 

Loop variable initialised 

while(expression) 

Body of the loop; 

Update loop variable; 

Here the loop variable must be initialised out side the while loop. Then the expression is evaluated if it is true then only the body of the loop will be executed and the loop variable must be updated inside the body. The body of the loop will be executed until the expression becomes false.

Eg.

i=1; 

j=1; 

while(i<=10)

couti<<i<<"*"<<j<<"="<<i*j;

i++;

j++; 

3. do While loop: 

It is an exit controlled loop. 

The syntax is given below 

do 

{

Statements 

}while(expression); 

Here the body executes at least once even if the condition is false. After executing the body it checks the expression if it false it quits the body otherwise the process will be continue.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...