0% found this document useful (0 votes)
11 views8 pages

Oindrila C Project

Uploaded by

gouravghosh0001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Oindrila C Project

Uploaded by

gouravghosh0001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Acknowledgement

We would like to express our sincere gratitude to the following individuals and organizations for their
invaluable contributions to this report:

* Pallab Sen for their guidance and support throughout the research process.

* Pallab Sen for providing technical expertise and assistance.

* EIILM KOLKATA Library for access to essential research materials.

* EIILM KOLKATA for their specific contributions to the report. We would also like to thank our peers
and classmates for their insightful feedback and collaborative spirit.
Flowchart of a For Loop in C

Here's a flowchart illustrating the working of a for loop in C programming:

Explanation:
1. Initialization:

* The loop variable is initialized with a starting value.

2. Condition Check:

* The condition is evaluated to determine if the loop should continue.

3. Body Execution:

* If the condition is true, the statements within the loop body are executed.

4. Update:

* The loop variable is updated according to the update expression.


5. Repeat:

* The process returns to step 2, where the condition is checked again.

6. Termination:

* The loop terminates when the condition becomes false.

Example:

for (int i = 1; i <= 5; i++) {

printf("%d ", i);

In this example:

* Initialization: int i = 1 initializes the variable i to 1.

* Condition Check: i <= 5 checks if i is less than or equal to 5.

* Body Execution: printf("%d ", i) prints the current value of i.

* Update: i++ increments the value of i by 1.

The loop continues until i becomes greater than 5.

Key Points:

* The for loop is a versatile control flow statement that allows you to execute a block of code
repeatedly.

* It's often used for iterating over arrays, processing lists, and performing repetitive tasks.

* The three components of a for loop (initialization, condition, and update) provide a concise and
efficient way to control the loop's behavior.

By understanding the flowchart and the example, we can effectively use for loops in your C programs
to write efficient and well-structured code.

Types of Loops in C:

* For Loop:

* Ideal for a fixed number of iterations.


* Initialization, condition, and update statements are defined within the loop header.

* While Loop:

* Executes as long as a given condition remains true.

* The condition is checked before each iteration.

* Do-While Loop:

* Executes at least once, and then continues as long as a given condition remains true.

* The condition is checked after each iteration.

Visual Representation (Flowchart):

For Loop code example:

#include <stdio.h>
int main() {

int i;

for (i = 1; i <= 10; i++) {

printf("%d ", i);

printf("\n");

return 0;

While Loop code example:

#include <stdio.h>
int main() {

int i = 1;

while (i <= 10) {

printf("%d ", i);

i++;

printf("\n");

return 0;

Do-While code example:

#include <stdio.h>
int main() {

int i = 1;

do {

printf("%d ", i);

i++;

} while (i <= 10);

printf("\n");

return 0;

}
Conclusion:

By understanding the flowcharts and syntax of these loops, programmers can effectively control the
flow of their programs and write efficient code. The choice of loop depends on the specific
requirements of the task, such as the number of iterations and the desired behaviour.

You might also like