Loops in C Programming, Slides of C programming

Clears Your Basics of Loops in C Programming

Typology: Slides

2025/2026

Available from 06/08/2026

rakib-chowdhury
rakib-chowdhury 🇧🇩

5 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Loops in C
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Loops in C Programming and more Slides C programming in PDF only on Docsity!

Loops in C

Loops in programming are used to repeat a block of code until the specified

condition is met. A loop statement allows programmers to execute a statement or

group of statements multiple times without repetition of code.

There are mainly two types of loops in C Programming:

1. Entry Controlled loops: In Entry controlled loops the test condition is

checked before entering the main body of the loop. For Loop and While Loop

is Entry-controlled loops.

1. Exit Controlled loops : In Exit controlled loops the test condition is evaluated

at the end of the loop body. The loop body will execute at least once,

irrespective of whether the condition is true or false. do-while Loop is Exit

Controlled loop.

Example:

for(int i = 0; i < n; ++i)

printf("Body of for loop which will execute till n");

In for loop, a loop variable is used to control the loop. Firstly we initialize the loop variable with

some value, then check its test condition. If the statement is true then control will move to the body

and the body of for loop will be executed. Steps will be repeated till the exit condition becomes

true. If the test condition will be false then it will stop.

Initialization Expression: In this expression, we assign a loop variable or loop counter to some

value. for example: int i= 1 ;

Test Expression: In this expression, test conditions are performed. If the condition evaluates to

true then the loop body will be executed and then an update of the loop variable is done. If the test

expression becomes false then the control will exit from the loop. for example, i<= 9 ;

Update Expression: After execution of the loop body loop variable is updated by some value it

could be incremented, decremented, multiplied, or divided by any value.

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

Loop control statements in C programming are used to change execution from its

normal sequence.

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.