Tamil Nadu Board of Secondary EducationHSC Science Class 11th

What is an entry control loop? Explain any one of the entry controlled loops with a suitable example. - Computer Science

Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Answer in Brief

What is an entry control loop? Explain any one of the entry-controlled loops with a suitable example.

Advertisement Remove all ads

Solution

In an entry-controlled loop, the test- expression is evaluated before entering into a loop, while and for statements are called as entry controlled loop.

Working of while loop:

A while loop is a control flow statement that allows the loop statements to be executed as long as the condition is true. The while loop ¡s an entry-controlled loop because the test-expression is evaluated before entering into a loop.

The while loop syntax is:

while (Test expression )
{
Body of the loop;
}
Statement-x;
In a while loop, the test expression is evaluated and if the test expression result is true, then the body of the loop is executed and again the control is transferred to the while loop. When the test expression result is false then control is transferred to statement-x.

The control flow and flow chart of the while loop is shown below.

 

Example:

#include <iostream>
using namespace std;
int main ()
{
int i=1,sum=0;
while(i<=10)
{
sum=sum+i;
i++;
}
cout<<“The sum of 1 to 10 is “<<sum; return 0;
}
Output
The sum of 1 to 10 is 55

Concept: Control Statements
  Is there an error in this question or solution?

APPEARS IN

Tamil Nadu Board Samacheer Kalvi Class 11th Computer Science Answers Guide
Chapter 10 Flow of Control
Evaluation - Section - D | Q 2. | Page 178
Share
Notifications

View all notifications


      Forgot password?
View in app×