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

While Loop in C programming

This article is about the while loop in C and the usage of it in C programs.

While loop in C

While loop tests the condition before executing the loop body. It repeats a statement or group of statements until a given condition is true.

In general, a while loop allows a part of the code to be executed multiple times depending upon a given condition. It can also be called as an iterating if statement. While loops are used when the number of iterations is unknown but the loop termination condition is known. If Condition is true, the flow re-iterates and when Condition is false, the flow exits the loop.

Condition Expression is mandatory in while loop and it is possible to run a while loop without the body. While loop allows us to have more than one conditional expression. Braces in the loop can be skipped if the body has only one statement.

Syntax

while (condition) 
{
    //statements inside the body of the loop 
}

Example

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

Output

 1 2 3 4 5 
← Loops OverviewFor Loop →
  • While loop in C
  • 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