









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Clears Your Basics of Loops in C Programming
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










for loop code #include int main() { int i = 0; for (i = 1; i <= 10; i++) { printf( "Hello World\n"); } return 0; }
While loop While loop does not depend upon the number of iterations. In for loop the number of iterations was previously known to us but in the While loop, the execution is terminated on the basis of the test condition. If the test condition will become false then it will break from the while loop else body will be executed. Syntax initialization_expression; while (test_expression) { // body of the while loop update_expression; }
While loop code #include int main(){ // Initialization expression int i = 2 ; // Test expression while(i < 10 ){ // loop body printf( "Hello World\n"); // update expression i++; } }
do-while loop The do-while loop is similar to a while loop but the only difference lies in the do-while loop test condition which is tested at the end of the body. In the do-while loop, the loop body will execute at least once irrespective of the test condition. Syntax: initialization_expression; do { // body of do-while loop update_expression; } while (test_expression);
do-while code #include int main(){ // Initialization expression int i = 2; do { // loop body printf( "Hello World\n"); // Update expression i++; // Test expression } while (i < 1); }
Loop Control Statements
Name Description break statement the break statement is used to terminate the switch and loop statement. It transfers the execution to the statement immediately following the loop or switch. continue statement (^) continue statement skips the remainder body and immediately resets its condition before reiterating it. goto statement (^) goto statement transfers the control to the labeled statement.