Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

While loop in C programming language

Posted on August 30, 2017January 24, 2020

Table of Contents

    • While loop in C programming language
    • flow diagram
  • How while loops works
    • Infinite loop

While loop in C programming language

In this tutorial, we will discuss the While loop in C programming language

In the C Programming Language, the while is used to evaluates test condition and executes the statement(s) until the Boolean condition becomes true. When the condition becomes false, control exit the loop and goes to the next statement after the while.

Syntex
whileTest_Expression)
{
//Body of while
    //statements

}

"While

flow diagram

"While

How while loops works

Initially, the while loop evaluates the test expression inside the parenthesis

if the test expression is true, codes inside the body of while loop are executed and the test expression is evaluated again until the test expression becomes false

when the test expression becomes false the loop control exits from the loop and loop terminated

Program 1

This program displays positive numbers of 1 to 10

 

"While

The above code is executed, it produces the following result

1
2
3
4
5
6
7
8
9
10

 

Program 2

while loop using logical or operator

"While

logical OR (||) operator executes when anyone become true
The above code is executed, it produces the following result
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

 

Infinite loop

"While

When value >=5, the loop would never end.
The above code is executed, it produces the following result
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
……..
………
ctr+c – to end the execution
While Loop in Java      while Loop in C++     While Loop In C

Do-while in Java    Do-while in C++      Do-while in C 

For Loop in C++       For Loop in C         For loop in java

If condition C++       If condition in Java   If condition in C

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes