C language Loop Statements

Interview Questions on C language Loop Statements


1. What is a loop statement in C?

Loop statement is used to execute a set of instructions repeatedly until a particular condition is being satisfied.

2. What are Control structures in C?

Control structures are the statements which controls the overall any program.

3. What are the different types of Control structures in C?

Control structures are basically of three types.
1. Sequence statements.
2. Iterative statements.
3. Selection statements.

4. What are Sequence Statements?

Sequence Statements are generally the individual statements, which performs the task of input, output, assignment declaration etc.

5. What are Iterative Statements?

Iterative Statements are those repeated execution of a particular set of instructions desired number of times. These statements are generally called loops for their execution nature.  Loops are basically of two types.
1. Count Loop.
2. Event Loop.

6. What are Count Loops?

Count Loops are those loops whose number of times of execution is known prior to the execution of loop are termed as count loops i.e they care countable in nature.

7. What are Event Loops?

Event Loops are those loops whose execution any certain event are called event before the execution.

8. What statements basically loops contain?

A loop basically consists of a loop variable which has for the completion of any iterative   statement, i.e a loop consists of three main statements:
1. Initialization.
2. Condition.
3. Incrementation.

9. What is initialization of a loop?

Initialization is used to start any loop i.e. it gives some initial value to the loop variable, which defines that from which value the loop has to get start.

10. What is condition and incrementation of a loop?

Condition is provided to give the final value to the loop variable so that how many times the loop has to get executed. For reaching the loop variable from initial value to the final value there should be some sort of incrementation and that provided by the third component statement of loop and that is incrementation.

11. What are the different types of looping statements?

The types of looping statements depend on the condition checking mode. Condition checking can be made in two ways. There are 2 types of looping statements.
1. Entry controlled loop.
2. Exit controlled loop.

12. What is Entry controlled loop?

In Entry controlled loop, the test condition is checked first before the loop is executed.
The Entry controlled loop statements are:
1. While loop.
2. For loop.

13. What is Exit controlled loop?

Exit controlled loop, the loop is executed first. Then condition is checked after block of statements are executed. The loop executed at least one time compulsorily. The exit controlled loop statement is:
1. Do-while loop.

14. Explain about For Loop statement?

In for looping statement, it allows a number of lines represent until the condition is satisfied.
Syntax:
for(initialization; condition ; increment/decrement variable)
{
Statement1;
...
Statement n;
}

15. Explain three parts of For Loop?

A for loop is made up of 3 parts inside its brackets which are separated by semi-colons. The first part initializes the loop variable. The loop variable controls and counts the number of times a loop runs. The second part of for loop is the condition a loop must meet to keep running. The third part is the loop variable incremental. This is called incrementing.

16. Explain For Loop with an example?

int main()
{
int i;
for (i = 1;i <= 20;i++)
printf("H\n");
return 0;
}

17. Explain about While Loop?

In while looping statement, it allows a number of lines represent until the condition is satisfied.
Syntax:
While (condition)
{
Statement1;
...
Statement n;
}

18. Write an example program using while loop?

#include<stdio.h>

int main()
{
int i, times;
scanf("%d",&times);
i = 0;
while (i <= times)
{
i++;
printf("%d\n",i);
}
return 0;
}

19. Explain about Do While Loop statement?

In Do While Loop statement, first it executes the statements then it checks the condition.
Syntax:
do
{
Statement1;
...
Statement n;
}
while(condition);
In this loop the condition is checked at the end, and for this reason this loop will execute at least once whether the condition may be satisfying and unsatisfying.

20. Give an example program using Do While Loop?

#include<stdio.h>

int main()
{
int i,times;
scanf("%d",&times);
i = 0;
do
{
i++;
printf("%d\n",i);
}
while (i <= times);
return 0;
}

21. What is a Break statement in C?

You can exit out of a loop at any time using the break statement. This is useful when you want a loop to stop running because a condition has been met other than the loop end condition.

22. What is a Continue statement in C?
You can use continue to skip the rest of the current loop and start from the top again while incrementing the loop variable again.

23. What is nested loop?
A loop inside another loop is known as nested loop. We can write any loop inside any loop in c i.e. we can write for loop inside the loop or while loop or do while loop etc.

24. Give an example for Nested Loop?
#include<stdio.h>
int main(){
int i,j,k;
     for(i=0;i<3;i++){
         for(j=0;j<3;j++){
             printf(" %d",i+j);
         }
    }
return 0;      
}

-------------------------------
C Language Interview Questions

Interview Questions on C Language Overview

Interview Questions on C Language Data Types

Interview Questions on C Language Variables
 

Interview Questions on C Language Constants

Interview Questions on C Language Operators

Interview Questions on C Language Conditional Statements
 

Interview Questions on C Language Built-in Functions

Interview Questions on C Language User defined Functions

Interview Questions on C Language Pointers

Working with Files

Working with Databases

Interview Questions on C Data Structures

Comments

Programming Examples 

0 comments:

Post a Comment