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
+1 vote
895 views
in Computer by (49.6k points)

Explain ‘while’ loop structure with an example.

1 Answer

0 votes
by (52.3k points)
selected by
 
Best answer

A ‘while’ loop statement repeatedly executes a statement or sequence of statements written in the flower brackets as long as a given condition returns the value ‘true’.

Syntax: The syntax of a ‘while’ loop in C++ is: while(condition)

{

statement (s) ;

}

Here the condition may be any expression, and for true is any non zero value. The loop iterates while the condition is true. When the condition becomes false, program control passes to the line immediately following the loop. During the first attempt, when the condition is tested and the result is false, the loop body will be skipped and the first statement after the ‘while’ loop will be executed.

Example: #include<iostream>

int main ()

{

int a = 10;

while (a<15)

{

cout <<"value of a:"<<a<<end1;

a++;

}

return 0;

}

When the above code is executed, it produces the following result:

value of a: 10

value of a: 11

value of a: 12

value of a: 13

value of a: 14

Related questions

+1 vote
1 answer
+1 vote
1 answer
+1 vote
1 answer

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

...