ENTRY CONTROL LOOP IN CAn entrance control loop first confirms the termination state at the entry point. If the termination condition or test expression is satisfied, control shifts to the while or for loop's main body. This loop type typically controls the entrances to the "while" and "for" loops. As a result, it is referred to in C as an entrance control loop. While loop:The "while" loop is the most simple looping structure in C. A looping entry control structure is the "while" loop. The program command is constantly performed until the specified termination condition is false using the "while" loop. When entering the "while" loop, the supplied test expression or termination condition is checked to see if it is true; if it is, the control is sent to the loop's main body. The statements written in the "while" loop's main body will then be carried out. The supplied test expression and termination condition will be evaluated once more as the counter changes the value to enter in the while loop. This process will be repeated until the supplied phrase is determined to be untrue. The starting termination condition is what makes up the "while" loop. Because of this, the while loop in C is also known as the entry-controlled loop. Syntax: Program: Output: Enter No. 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 is the most effective and adaptable looping structure in C. The "for" loop allows us to easily complete any challenging work in C. Syntax: The "for-loop" is made up of three primary components, which are described below:
With the aid of the initialization statement, a counter variable is set up at the start of the loop execution. The termination condition is then reviewed, which is specified in the expression part. The main body of the "for" loop will automatically take over if the termination condition is found to be true. The program statements included within the "for" loop would then be executed. The final step will involve moving control to the third section to change the counter value (either by increasing or decreasing the amount). After the value has been modified, the counter value will be assessed through the termination condition to determine whether the control can enter the "for" loop and be executed. The entire process described above will repeat itself until the termination condition's outcome is false, at which point it will stop. The control will bypass the entire "for" loop and execute the statement line that was written immediately after the "for" loop when the test expression yields a false value. Example: Program: The for loop in the following program allows the user to print a multiplication table for a natural number. Output: Enter No. to print Table : 8 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24 8 * 4 = 32 8 * 5 = 40 8 * 6 = 48 8 * 7 = 56 8 * 8 = 64 8 * 9 = 72 8 * 10 = 80 Conclusion:In conclusion, the entry control loop is a crucial component of the C programming language and offers a quick and effective approach to manage loop execution. Next TopicEXIT CONTROL LOOP IN C |