While loop Syntax Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report While loop is a fundamental control flow structure (or loop statement) in programming, enabling the execution of a block of code repeatedly as long as a specified condition remains true. Unlike the for loop, which is tailored for iterating a fixed number of times, the while loop excels in scenarios where the number of iterations is uncertain or dependent on dynamic conditions. Table of Content While loop Syntax in C/C++Java While loop SyntaxWhile loop Syntax in PythonWhile loop Syntax in C#While loop Syntax in JavaScriptThe syntax of While loop varies slightly depending on the programming language, but the basic structure is similar across many languages. while (condition) { // Code block to be executed repeatedly as long as the condition is true }Here’s a general overview of the Syntax of While loop: Condition: This is the condition that is evaluated before each iteration of the loop. If the condition is true, the loop body is executed; otherwise, the loop terminates.Loop Body: This is the block of code that gets executed if the condition is true.Update: Inside the loop body, there should be some logic to change the variables involved in the condition so that the loop eventually terminates. Otherwise, you risk creating an infinite loop.While loop Syntax in C/C++:Syntax:while (condition) { // Code block to be executed repeatedly as long as the condition is true }Explanation of the Syntax:In C and C++, the while loop executes a block of code repeatedly as long as the specified condition evaluates to true.The loop first evaluates the condition specified within the parentheses ().If the condition is true, the code block within the curly braces {} is executed.After executing the code block, the loop returns to the beginning and re-evaluates the condition.If the condition remains true, the process continues; otherwise, the loop terminates.Implementation of While loop Syntax in C/C++: C++ #include <iostream> using namespace std; int main() { int i = 0; while (i < 10) { cout << i << " "; i++; } return 0; } C #include <stdio.h> int main() { int i = 0; while (i < 10) { printf("%d ", i); i++; } return 0; } Output0 1 2 3 4 5 6 7 8 9 Java While loop Syntax:Syntax:while (condition) { // Code block to be executed repeatedly as long as the condition is true } Explanation of the Syntax:In Java, the while loop operates similarly to C and C++.It first evaluates the condition specified within the parentheses ().If the condition is true, the code block within the curly braces {} is executed.After executing the code block, the loop returns to the beginning and re-evaluates the condition.If the condition remains true, the process continues; otherwise, the loop terminates.Implementation of While loop Syntax in Java: Java /*package whatever //do not write package name here */ import java.io.*; class GFG { public static void main(String[] args) { int i = 0; while (i < 10) { System.out.print(i + " "); i++; } } } Output0 1 2 3 4 5 6 7 8 9 While loop Syntax in Python:Syntax:while condition: # Code block to be executed repeatedly as long as the condition is true Explanation of the Syntax:Python's while loop follows a similar structure to other languages.It begins by evaluating the condition specified after the while keyword.If the condition is true, the code block indented below is executed.After executing the code block, the loop returns to the while statement and re-evaluates the condition.If the condition remains true, the process continues; otherwise, the loop ends.Implementation of While loop Syntax in Python: Python3 i = 0 while i < 10: print(i, end=" ") i += 1 Output0 1 2 3 4 5 6 7 8 9 While loop Syntax in C#:Syntax:while (condition) { // Code block to be executed repeatedly as long as the condition is true } Explanation of the Syntax:In C#, the while loop behaves similarly to C, C++, and Java.It starts by evaluating the condition specified within the parentheses ().If the condition is true, the code block within the curly braces {} is executed.After executing the code block, the loop returns to the beginning and re-evaluates the condition.If the condition remains true, the process continues; otherwise, the loop terminates.Implementation of While loop Syntax in C#: C# using System; public class GFG { static public void Main() { int i = 0; while (i < 10) { Console.Write(i + " "); i++; } } } Output0 1 2 3 4 5 6 7 8 9 While loop Syntax in JavaScript:Syntax:while (condition) { // Code block to be executed repeatedly as long as the condition is true } Explanation of the Syntax:JavaScript's while loop follows the same pattern as other languages.It evaluates the condition specified within the parentheses () before each iteration.If the condition is true, the code block within the curly braces {} is executed.After executing the code block, the loop returns to the beginning and re-evaluates the condition.If the condition remains true, the loop continues; otherwise, it ends.Implementation of While loop Syntax in JavaScript: JavaScript let i = 0; while (i < 10) { console.log(i + " "); i++; } Output0 1 2 3 4 5 6 7 8 9 Comment More infoAdvertise with us Next Article Computer Hardware C code_r Follow Improve Article Tags : Computer Science Fundamentals Similar Reads Computer Fundamentals Tutorial This Computer Fundamentals Tutorial covers everything from basic to advanced concepts, including computer hardware, software, operating systems, peripherals, etc. Why Learn Computer FundamentalsYour computer can solve complex problem in milliseconds!Helps you understand how computers work and solve 4 min read FundamentalComputer HardwareComputer hardware refers to the physical components of a computer that you can see and touch. These components work together to process input and deliver output based on user instructions. In this article, weâll explore the different types of computer hardware, their functions, and how they interact 10 min read What is a Computer Software?Computer Software serves as the backbone of all digital devices and systems. It is an integral part of modern technology. Unlike hardware which comprises physical components, software is intangible and exists as a code written in programming language. This article focuses on discussing computer soft 8 min read Central Processing Unit (CPU)The Central Processing Unit (CPU) is like the brain of a computer. Itâs the part that does most of the thinking, calculating, and decision-making to make your computer work. Whether youâre playing a game, typing a school assignment, or watching a video, the CPU is busy handling all the instructions 6 min read Input DevicesInput devices are important parts of a computer that help us communicate with the system. These devices let us send data or commands to the computer, allowing it to process information and perform tasks. Whether it's typing on a keyboard or clicking a mouse, these devices enable us to interact with 11 min read Output DevicesOutput devices are hardware that display or produce the results of a computer's processing. They convert digital data into formats we can see, hear, or touch. The output device may produce audio, video, printed paper or any other form of output. Output devices convert the computer data to human unde 9 min read MemoryComputer MemoryMemory is the electronic storage space where a computer keeps the instructions and data it needs to access quickly. It's the place where information is stored for immediate use. Memory is an important component of a computer, as without it, the system wouldnât operate correctly. The computerâs opera 9 min read What is a Storage Device? Definition, Types, ExamplesThe storage unit is a part of the computer system which is employed to store the information and instructions to be processed. A storage device is an integral part of the computer hardware which stores information/data to process the result of any computational work. Without a storage device, a comp 11 min read Primary MemoryPrimary storage or memory is also known as the main memory, which is the part of the computer that stores current data, programs, and instructions. Primary storage is stored in the motherboard which results in the data from and to primary storage can be read and written at a very good pace.Need of P 4 min read Secondary MemorySecondary memory, also known as secondary storage, refers to the storage devices and systems used to store data persistently, even when the computer is powered off. Unlike primary memory (RAM), which is fast and temporary, secondary memory is slower but offers much larger storage capacities. Some Ex 7 min read Hard Disk Drive (HDD) Secondary MemoryPrimary memory, like RAM, is limited and volatile, losing data when power is off. Secondary memory solves this by providing large, permanent storage for data and programs.A hard disk drive (HDD) is a fixed storage device inside a computer that is used for long-term data storage. Unlike RAM, HDDs ret 11 min read Application SoftwareMS Word Tutorial - Learn How to Use Microsoft Word (2025 Updated)Microsoft Word remains one of the most powerful word processing program in the world. First released in 1983, this word processing software has grown to serve approximately 750 million people every month. Also, MS Word occupies 4.1% of the market share for productivity software.With features like re 9 min read MS Excel Tutorial - Learn Excel Online FreeExcel, one of the powerful spreadsheet programs for managing large datasets, performing calculations, and creating visualizations for data analysis. Developed and introduced by Microsoft in 1985, Excel is mostly used in analysis, data entry, accounting, and many more data-driven tasks.Now, if you ar 11 min read What is a Web Browser and How does it Work?The web browser is an application software used to explore the World Wide Web (WWW). It acts as a platform that allows users to access information from the Internet by serving as an interface between the client (user) and the server. The browser sends requests to servers for web documents and servic 4 min read What is a Excel SpreadsheetExcel works like other spreadsheet programs but offers more features. Each Excel file is called a workbook, which contains one or more worksheets. You can start with a blank workbook or use a template.A worksheet is a grid of 1,048,576 rows and 16,384 columns, over 17 billion cells, for entering and 7 min read System SoftwareWhat is an Operating System?An Operating System is a System software that manages all the resources of the computing device. Acts as an interface between the software and different parts of the computer or the computer hardware. Manages the overall resources and operations of the computer. Controls and monitors the execution o 5 min read Windows 10 TutorialExplore our Free Windows 10 Tutorial to learn how to use Microsoft Operating System-Windows 10 remains one of the most widely used operating systems, offering a balance of performance, security, and user-friendly features. Whether you're a new user setting up your PC for the first time or someone lo 15+ min read Linux/Unix TutorialLinux is one of the most widely used open-source operating systems. It's fast, secure, stable, and powers everything from smartphones and servers to cloud platforms and IoT devices. Linux is especially popular among developers, system administrators, and DevOps professionals.Linux is:A Unix-like OS 10 min read Top 10 iOS App Development Tools That You Can ConsiderBusinesses know the importance of being in close proximity to their customers. And the closest thing to the customers today is their smartphones. Smartphones are also the means for businesses to get as close to customers as they possibly can. Mobile applications are the fastest way for businesses to 7 min read What is macOS?macOS is built on a Unix based architecture and provides users with a reliable and user friendly experience. In this article, we will understand macOS in detail. What is macOS?macOS operating system that Apple Inc. developed especially for its Macintosh computer series. It is the replacement for the 4 min read Programming LanguagesC Programming Language TutorialC is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used 5 min read Python Tutorial - Learn Python Programming LanguagePython is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo 10 min read Java TutorialJava is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. Known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Syntax and s 10 min read JavaScript TutorialJavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.Client Side: On the client side, JavaScript works 11 min read Like