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
185 views
in Computer by (43.6k points)
closed by

What is looping? Write about the different statements used to erect loop in ‘C’?

1 Answer

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

Looping

Looping Statements: A computer program is a set of statements, which is normally executed sequentially. But in most of the cases, it is necessary to repeat certain steps to meet a specific condition. This repetitive operation is done through a loop control structure. A loop is basically the execution of the sequence of statements repeatedly until a particular condition is true or false. In ‘C’ language following looping statements are used:

while Statements: The while loop repeats a statement or a set of statements until a certain condition is true. Syntax

while (condition)

{

statements

}

Here, the condition may be any expression having a non-zero value. The loop continues until the condition is true. When the condition fails, the program body attached with loop (statements), will not be executed.

Example: To print the first 20 natural numbers.

#include<stdio.h>

#include<conio.h>

void main ()

{

int a = 1;

while (a < = 20)

{

printf (“%d” , a);

a++;

}

getch ();

}

do-while statement: Working of this statement is similar to the working of while statement but in this, at least one time the attached loop (statements) is executed, no matter whether the condition is true or false.

Synax:

do

{

statements

}

while (condition);

Example: To print first 10 odd numbers.

#include<stdio.h>

#include<conio.h>

void main ()

{

int a = 1;

do

{

printf (“% d” , a);

a+ = 2;

{while (a <=19)};

}

for loop statement:

The for loop is an ideal looping statement when we know how many times the loop will be executed.

Syntax:

for (initialization; condition; counter)

{

statements

}

Here,

  • Initialization is generally an assignment which is used to set the loop control variable, e.g., a = 0.
  • Condition always tells the limit of the loop or determines when to exit the loop. e.g., a < 10
  • Counter defines how the loop control variable will change each time the loop is repeated. This may be incremented or decremented. e.g., a++, a- -.

Example: To print your name 10 times.

#include<stdio.h>

#include<conio.h>

void main ()

{

int i;

char name [20];

clrscr ();

printf (“Enter your name”);

gets(name);

for (i = 1; i <= 10; i++)

puts (name);

}

getch ();

}

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 21, 2022 in Computer by ParneetNain (43.6k points)
0 votes
1 answer
asked Jun 21, 2022 in Computer by ParneetNain (43.6k points)

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

...