CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Loop

C Programming

    Introduction

    • Overview
    • Installation & Setup
    • C Program Structure
    • Keywords & Identifiers
    • Data Types
    • Variables & Constants
    • Scope Rules
    • Storage Class
    • Standard Input and Output
    • Operators

    Control Flow/Decision Making

    • Overview
    • if Statement
    • if else Statement
    • Nested If statement
    • Switch Statement
    • Nested Switch Statement
    • Conditional Operators

    Loop

    • Loops Overview
    • While loop
    • For Loop
    • Do while
    • Nested Loops
    • Break
    • Continue Statement
    • Goto statement

    Arrays

    • Arrays
    • Multi Dimensional Arrays
    • Arrays & Functions

    Pointers

    • Pointers Basics
    • Pointers and Arrays
    • Pointers and Functions
    • Memory allocation

    Strings

    • String Basics
    • String Functions

    C Programming Examples

    • Basic Example 1

For Loop in C

This article is about the for loop in C programming and how it can be used in your programs.

Introduction - For Loop

For loop is a repetition control structure that executes a sequence of statements multiple times as required for the program.

In for loop, the initialization is done only once and then the condition is checked. If the condition returns true, statements inside the body of the loop are executed and then the update statement is performed and again evaluates the condition.

But if the condition returns false then the loop is terminated. The ‘for loop’ in the C language is basically used to iterate the statements or the part of a program repeated times. For loop can be used when the number of iterations are known. i.e number of times the statements to be executed.

Syntax

for (initialization Statement; condition; update Statement)
{
    //statements inside the body of loop
}

Example

#include <stdio.h>
int main()
{
    int i = 1;
    while (i <= 7)
    {
        printf("%d ", i);
        ++i;
    }
    return 0;
}

Output

1 2 3 4 5 6 7
← While loopDo while →
  • Introduction - For Loop
  • Syntax
  • Example
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com