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
42 views
in C++ by (25 points)
int n=5;

while ( n<=10)

{

      n++;

}

Please log in or register to answer this question.

1 Answer

0 votes
by (13.8k points)
int n = 5;
while (n <= 10) {
    n++;
}

The loop condition is n <= 10, which means the loop will continue executing as long as the value of n is less than or equal to 10.

Initially, n is assigned the value of 5. In each iteration of the loop, n is incremented by 1 (n++). The loop will continue executing until n is no longer less than or equal to 10.

Here's how the loop will execute:

  1. When n is 5, the condition n <= 10 is true, so the loop executes once. After this iteration, n becomes 6.
  2. When n is 6, the condition n <= 10 is true, so the loop executes again. After this iteration, n becomes 7.
  3. When n is 7, the condition n <= 10 is true, so the loop executes again. After this iteration, n becomes 8.
  4. When n is 8, the condition n <= 10 is true, so the loop executes again. After this iteration, n becomes 9.
  5. When n is 9, the condition n <= 10 is true, so the loop executes again. After this iteration, n becomes 10.
  6. When n is 10, the condition n <= 10 is true, so the loop executes again. After this iteration, n becomes 11.

After the sixth iteration, n becomes 11, and the condition n <= 10 evaluates to false. Therefore, the loop stops executing.

So, the loop gets executed 6 times.

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

...