Professional Documents
Culture Documents
Experiment 8
2. Tools used:
3. Theory :
Loop control statements in C are used to perform looping operations until the given condition is
true. Control comes out of the loop statements once condition becomes false.
Prof.Shweta Mahajan
1. For Loop
A for loop is a repetition control structure that allows you to efficiently write a loop that
needs to execute a specific number of times.
Syntax:
Next, the test_expression is evaluated. If it is true, the body of the loop is executed. If it
is false, the body of the loop is not executed and the flow of control jumps to the next
statement just after the 'for' loop.
After the execution of body of the 'for' loop, the flow of control jumps back up to the
update_expression statement. This statement allows you to update any loop control
variables. This statement can be left blank, as long as a semicolon appears after the
test_expression.
The test_expression is now evaluated again. If it is true, the loop executes and the process
repeats itself (body of loop, then increment step, and then again condition). After the
test_expression becomes false, the 'for' loop terminates.
Example:
Prof.Shweta Mahajan
Output:
Program:
Write a Program to calculate the sum of first n natural numbers(Positive integers 1,2,3...n
are known as natural numbers) using for loop.
Prof.Shweta Mahajan
Output:
5. Exercise: Write a program to calculate factorial integer number using for loop.
Prof.Shweta Mahajan