×

Entry Control Loop in C

Initially, an entry control loop verifies the termination condition at the entry point. After that, its control passes to the main body of the while or for loop if the termination condition or test expression becomes true. This kind of loop usually regulates the ‘while’ and ‘for’ loop entrance. Due to this, it is known as an entry control loop in C.

ENTRY CONTROL LOOP IN C

                                              Diagram:  Entry control loop in C

While loop:

C’s most straightforward looping form is none other than the “while” loop. The “while” loop is a looping entry control arrangement.

The “while” loop is used to run the program command continuously until the provided termination condition is false.

The specified test expression or termination condition will be examined at the time of entrance in the “while” loop, and if it finds out to be true, then the control will be moved to the main body of the “while” loop.

After that, the statements written within the main body of the “while” loop will be executed.

 The counter will change the value to enter in the while loop, and the specified test expression/ termination condition will be evaluated once again. This procedure will be repeated until the supplied phrase is found to be false. The "while" loop consists of the termination condition portion in starting.

That's why the while loop is called the entry-controlled loop in C.

Syntax:

while(termination condition)
{
    // main body of the "while" loop 
}
while( i <= 10) // initialization statement
{
    printf("\n  Value of I is %d", i) ;
    i++ ;      // modifying (increment/ decrement statement) counter value
}

Program:

#include "stdio.h" 
#include "conio.h" 
void main()
{
    int n, i, ans; // declaring integers
    clrscr();
    printf("\n Enter No. to print Table : ");
    scanf("%d", &n); // assigning value to n entered by user
    i = 1; // setting 1 as the counter value  
    while(i <= 10) // termination condition
    {
       ans = n * i;
       printf("\n  %d * %d = %d", n,i, ans) ;
              i++;      // modifying (increment/ decrement statement) counter value
    }
    getch();
}

Example:

For loop:

C's most powerful and versatile looping structure is none other than the “for” loop. With the help of the “for” loop, we may easily accomplish any difficult task in C.

Syntax:

for (initialization statement; termination condition; increment/decrement statement)
 {
       // main body of the "for" loop in C
 }

There are three main parts of the "for-loop", which are mentioned below:

1. Initialization statement,

2. Termination condition, and

3. Increment or decrement statement.

Initially, when the execution of the loop takes place, a counter variable is initiated with the help of the initialization statement. After that, the termination condition, which is given inside the expression section, is examined.

If the termination condition finds to be true, the control will be automatically entered into the main body of the “for” loop. And, at last, the program statements written inside the “for” loop would likely be executed.

In the last step, the control will be transferred to the third portion to modify the counter value (either for incrementing or decrementing the value).

The counter value will be evaluated through the termination condition after the modification of the value and will check that the control can enter into the "for" loop for execution.

The entire procedure explained above will run again and again until and unless the result of the termination condition becomes false.

When the test expression returns a false value, the control will skip the whole "for" loop and executes the statement line which has been written just after the 'for' loop.

Example:

for (i=0; i<5; i++)
 {
    printf("Hello world!!!")   // main body of the "for" loop in C
 }

Program:

The following program enables the user to print a multiplication table of a natural number with the help of the “for” loop.

#include "stdio.h"
#include "conio.h"
void main()
{
    int n, a, ans; // declaring variables
    clrscr();
    printf("\n Enter No. to print Table : ");
    scanf("%d", &n); // assigning value to a entered by the user
    /* for(initialization condition, 
    termination condition, increment or decrement condition) */
    for(a = 1; a <=10 ; a++ )
    {
       ans = n * a;
       printf("\n  %d * %d = %d", n,a, ans) ;
    }
    getch();
}

Related Topics

getch() function in C

getch() is a pre-define or built-in function present in the conio.h library. It returns the given character immediately without waiting for the enter key to be entered. By using getch()...

3 minutes read.

Builtin functions of GCC compiler

Certain built-in functions are present in the GCC compiler. These features are as follows: Function_ built in_popcount (x) The number of 1s in data of the integer type can be counted using...

3 minutes read.

Find occurrence of substring in C using function

Introduction: In this article, we discuss finding the occurrence of a substring in C using function. This software takes strings and substrings as input and counts the occurrences of substrings within...

3 minutes read.

C pre-processor

The C processor is a macro processor which is used to compile the source code of the program (step by step) . It is not a part of the compiler....

4 minutes read.

#define in C

#define in C In the C programming language, the preprocessor directive acts an important role within which the #define directive is present that is used to define the constant or the...

3 minutes read.

10 Best IDEs for C or C++ Developers in 2024

Nobody can deny the fact that C and C++ were the first programming languages used by significant developers worldwide. Even now, newcomers who want to start programming are most frequently...

6 minutes read.

How to convert a number to words in C

There are many ways available for converting an integer or a number to its word form. For example, consider a number as 12345. This number can be represented in two...

3 minutes read.

Static function in C

The functions in the C programming language are by default global. This means the programmer can easily access the function which is outside from the file where it was initially...

3 minutes read.

Static in C

Static is a keyword that is used in the C programming language. It can be used both as variables and as functions. In other words, it can be declared both...

3 minutes read.

Return array from function in C

Return array from function in C C programming does not require the return to a function of a whole array as an argument. However, you can return a pointer to an array without...

2 minutes read.

Recursion in C

Recursion in C: In the C programming language, the concept known as recursion exists that is a technique in which a function calls itself either directly or indirectly. It allows...

4 minutes read.

Bank Account System in C using File Handling

This tells about the creation of bank account system using the C language and handling of files in C. Approach Let us see the approaches and the functions how they are covering...

5 minutes read.

Find median of 1D array using function in C

Introduction: Here, we discuss how we can find the median of a 1D array using a function in C. The median is the value in the middle of the sorted...

3 minutes read.

Pointer to pointer in C

A pointer to another pointer is another type of multiple indirections and a chain of many pointers. Generally, a pointer consists of the address of the variable. Once a pointer to...

4 minutes read.

Pi() Function in C

Pi: Mathematic constants are not defined in the c or c++ programming languages. To use the Mathematical constants firstly, we have to define the _USE_MATH_DEFINES and then declare the cmath and...

3 minutes read.

#error #pragma in C

#error, #pragma in C #error, also known as the error directive in the C language. It will not allow you to make any compilation fail and immediately issues a statement which...

4 minutes read.

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

Cbrt() function in C

Introduction: The Cbrt is a function used in C programming language. The cbrt() function is a math function. Using the cbrt function, we can do the cube root of a function. This...

4 minutes read.

Assert() Function in C

Assert (): In C, the statements are executed with the exit statement. In C language declare, and it tests the condition parameters. If the statement executed will be false, it...

3 minutes read.

Pure Virtual Function in C

Before knowing about the pure virtual function some of the important points about the virtual function in C++ are given below. In c++ the member function that is defined in the...

4 minutes read.