![]() |
In C programming, loops are responsible for performing repetitive tasks using a short code block that executes until the condition holds true. In this article, we will learn about for loop in C. for Loop in CThe for loop in C Language provides a functionality/feature to repeat a set of statements a defined number of times. The for loop is in itself a form of an entry-controlled loop. Unlike the while loop and do…while loop, the for loop contains the initialization, condition, and updating statements as part of its syntax. It is mainly used to traverse arrays, vectors, and other data structures. Syntax of for Loopfor(initialization; check/test expression; updation) { // body consisting of multiple statements } Structure of for LoopThe for loop follows a very structured approach where it begins with initializing a condition then checks the condition and in the end executes conditional statements followed by an updation of values.
How for Loop Works?The working of for loop is mentioned below:
Flowchart of for Loop![]() C for Loop Flow Diagram Example of for loopThe following program illustrates how to use for loop in C: C
Output
GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks Nested for loop in CC provides the feature of a nested loop where we can place a loop inside another loop. Syntaxfor( .. ; .. ; .. ){ for( .. ; .. ; .. ){ .... } } To know more about nested for loop refer to Nested for loop in C. Special Conditions1. for loop without curly bracesYou already know about for loop and its syntax, when we declare a for loop without curly braces, the loop executes only one statement which is written just after it, and the statement can not be declarative. Example C
Output
1 2 3 4 5 6 7 8 9 10 This statement executes after for loop end!!!! 2. Infinite for Loop/NULL Parameter LoopThis is also a kind of for loop where the input parameters are not available or do not exist by virtue of which the loop iterates/runs endlessly. Example C
Output: GeeksforGeeks to InfiniteGeeksforGeeks to InfiniteGeeksforGeeks to InfiniteGeeksforGeeks to InfiniteGeeksforGeeks to Infinite..... Advantages of for LoopThere are certain advantages of using for loops in C as mentioned below:
Disadvantages of for LoopDespite so many advantages of for loops it even has certain disadvantages:
ConclusionIn this article, the points we learned about for loops are mentioned below:
FAQs on for loops in C1. What is a loop?Answer:
2. How to do iteration in C programming?Answer:
3. How many types of looping statements are there in C Programming?Answer:
4. Can we use multiple variables in for loop?Answer:
5. How to make an infinite for loop in c?Answer:
|
Reffered: https://www.geeksforgeeks.org
C Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |