Entry Control Loop in C
0 217
An entry control loop evaluates the termination condition before entering the loop body.
It's commonly associated with "while" and "for" loops in C, controlling the loop's entry based on the condition's truth value.
While Loop
The "while" loop is the simplest looping construct in C, executing its body as long as the termination condition holds true.
It's referred to as an entry-controlled loop due to its condition being evaluated before entering the loop body.
Syntax of While Loop:
while (termination_condition) { // while loop body }Example:
// Program for while loop #include<stdio.h>#include<conio.h> void main() { int n, i, ans; printf("\nenter a number to print table: "); scanf("%d", &n); i = 1; while (i <= 10) { ans = n * i; printf("\n%d * %d = %d", n, i, ans); i++; } getch(); }
Output:
Enter a number to print table: 5 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50
for Loop
The "for" loop in C provides versatility and efficiency, encompassing an initialization statement, a termination condition, and an increment/decrement operation.Syntax of for loop in C:
for (initialization; termination_condition; increment/decrement) { // for loop body }Example:
// Program for for loop in C #include<stdio.h>#include<conio.h> void main() { int n, u, ans; printf("\nenter a number table: "); scanf("%d", &n); for (u = 1; u <= 10; u++) { ans = n * i; printf("\n%d * %d = %d", n, u, ans); } getch(); }
Output:
Enter a number to print table: 5 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50
Conclusion:
The entry control loop in C, demonstrated through "while" and "for" loops, provides efficient control over loop execution, making it an essential aspect of C programming for managing iterative tasks.
Share:
Comments
Waiting for your comments