Difference between while and do-while loop in C, C++, Java Last Updated : 17 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report while loop: A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement. Syntax :while (boolean condition){ loop statements...}Flowchart:Example: C++ #include <iostream> using namespace std; int main() { int i = 5; while (i < 10) { i++; cout << "GFG\n"; } return 0; } C #include <stdio.h> int main() { int i = 5; while (i < 10) { printf("GFG\n"); i++; } return 0; } Java import java.io.*; class GFG { public static void main(String[] args) { int i = 5; while (i < 10) { i++; System.out.println("GfG"); } } } OutputGFG GFG GFG GFG GFG do-while loop: do while loop is similar to while loop with the only difference that it checks for the condition after executing the statements, and therefore is an example of Exit Control Loop.Syntax:do{ statements..}while (condition);Flowchart:Example: C++ #include <iostream> using namespace std; int main() { int i = 5; do { i++; cout << "GFG\n"; } while (i < 10); return 0; } C #include <stdio.h> int main() { int i = 5; do { printf("GFG\n"); i++; } while (i < 10); return 0; } Java import java.io.*; class GFG { public static void main(String[] args) { int i = 5; do { i++; System.out.println("GfG"); } while (i < 10); } } OutputGFG GFG GFG GFG GFG Here is the difference table:whiledo-whileCondition is checked first then statement(s) is executed.Statement(s) is executed atleast once, thereafter condition is checked.It might occur statement(s) is executed zero times, If condition is false.At least once the statement(s) is executed.No semicolon at the end of while. while(condition)Semicolon at the end of while. while(condition);Variable in condition is initialized before the execution of loop.variable may be initialized before or within the loop.while loop is entry controlled loop.do-while loop is exit controlled loop.while(condition) { statement(s); }do { statement(s); } while(condition); Comment More infoAdvertise with us P pp_pankaj Follow Improve Article Tags : Java Difference Between Programming Language C Language C++ Computer Science Fundamentals DSA Loops & Control Structure +4 More Practice Tags : CPPJava Similar Reads DSA Tutorial - Learn Data Structures and Algorithms DSA (Data Structures and Algorithms) is the study of organizing data efficiently using data structures like arrays, stacks, and trees, paired with step-by-step procedures (or algorithms) to solve problems effectively. Data structures manage how data is stored and accessed, while algorithms focus on 7 min read Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is 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).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read C++ Programming Language C++ is a computer programming language developed by Bjarne Stroustrup as an extension of the C language. It is known for is fast speed, low level memory management and is often taught as first programming language. It provides:Hands-on application of different programming concepts.Similar syntax to 5 min read C Programming Language Tutorial C 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 Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Quick Sort QuickSort is a sorting algorithm based on the Divide and Conquer that picks an element as a pivot and partitions the given array around the picked pivot by placing the pivot in its correct position in the sorted array. It works on the principle of divide and conquer, breaking down the problem into s 12 min read Merge Sort - Data Structure and Algorithms Tutorials Merge sort is a popular sorting algorithm known for its efficiency and stability. It follows the divide-and-conquer approach. It works by recursively dividing the input array into two halves, recursively sorting the two halves and finally merging them back together to obtain the sorted array. Merge 14 min read Data Structures Tutorial Data structures are the fundamental building blocks of computer programming. They define how data is organized, stored, and manipulated within a program. Understanding data structures is very important for developing efficient and effective algorithms. What is Data Structure?A data structure is a st 2 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Like