The do while loop executes the content of the loop once before checking the condition of the while.

Whereas a while loop will check the condition first before executing the content.

In this case you are waiting for user input with scanf(), which will never execute in the while loop as wdlen is not initialized and may just contain a garbage value which may be greater than 2.

Answer from hydrogen on Stack Overflow
Discussions

Do/While vs. While loops?
The only difference is that a While loop body may not be executed at all (if condition is false before the first run), while a Do/While loop body is guaranteed to be executed at least once. More on reddit.com
🌐 r/csharp
31
27
March 10, 2022
I really don't get while, do-while, and for loops in C.
You're asking your question really abstractly so I'm having a hard time coming up with an answer but I'll give it a shot. Loops are used because you want to repeat an action while a condition is true or you want to repeat it on a certain number of things or a certain number of times. The answer to "how do you know how many times to repeat" isn't something you can really come up with without knowing what problem you're trying to solve. Say you want a user to input yes or no in response to a question. The user could also enter in "applesauce" or "bumblebee" because it's free text and they can type whatever they want. In that case you might use a while loop. While the user hasn't responded yes or no, you ask them again. You don't know how many times the user is going to put in the wrong answer. They could do it infinitely. Your while loop will diligently keep sending them the prompt again until the condition of them answering "yes" or "no" is satisfied. Maybe this doesn't answer your question though. Do you have a specific problem you were given where you were confused as to how many times to loop or how to write the condition? More on reddit.com
🌐 r/learnprogramming
94
67
November 27, 2023
Whats the diffrence between "do-while" loops and only "while" loops?
A do-while loop will always execute the "do" part at least once. It may execute many more times assuming the "while" condition is met. The while condition is tested AFTER the "do" statement. A while loop will only execute if the while condition is met and there is no guarantee that it will run at least once. More on reddit.com
🌐 r/learnprogramming
83
198
August 14, 2015
People also ask

What is a do-while loop?
A do-while loop is similar to a while loop but checks the conditions after executing the statement(s) at least once. It's an example of an Exit Control Loop.
🌐
testbook.com
testbook.com › home › key differences › difference between while and do while loop in c, c++ & java
Difference Between While and Do While Loop in C, C++ & Java
What is a while loop?
A while loop is a control flow statement that executes a code based on a given Boolean condition. It's a type of repeating statement that checks the condition before executing the statement(s).
🌐
testbook.com
testbook.com › home › key differences › difference between while and do while loop in c, c++ & java
Difference Between While and Do While Loop in C, C++ & Java
Which is Faster While or Do While?
The speed difference between while and do while loops is generally negligible. It's dependent on the specific use case and the compiler optimisations.
🌐
theknowledgeacademy.com
theknowledgeacademy.com › blog › difference-between-while-and-do-while
Difference Between While and Do While Loop in C, C++, & Java
🌐
Guru99
guru99.com › home › c programming › difference between while and do-while loop in c
Difference between while and do-while loop in C
November 8, 2024 - While loop allows initialization of counter variable before starting the body of a loop, whereas do while loop allows initialization of counter variable before and after starting the body of a loop.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_do_while_loop.htm
Do-While Loop in C
The do-while loop is one of the most frequently used types of loops in C. The do and while keywords are used together to form a loop. The do-while is an exit-verified loop where the test condition is checked after executing the loop's body. Whereas ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-while-and-do-while-loop-in-c-c-java
Difference between while and do-while loop in C, C++, Java - GeeksforGeeks
July 17, 2024 - 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.
🌐
Programiz
programiz.com › c-programming › c-do-while-loops
C while and do...while Loop
The do..while loop is similar to the while loop with one important difference. The body of do...while loop is executed at least once.
🌐
Testbook
testbook.com › home › key differences › difference between while and do while loop in c, c++ & java
Difference Between While and Do While Loop in C, C++ & Java
Both loops allow repetitive execution of a block of code as long as the given condition remains true. The key difference between while and do while loo[ lies in the time when the condition is checked.
Find elsewhere
🌐
Hero Vired
herovired.com › learning-hub › blogs › difference-between-while-and-do-while-loop-in-c
Difference Between While and Do While Loop in C
March 15, 2023 - The outer loop controls the number of rows printed, while the inner loop controls how many times the “HeroVired” message is printed in each row. ... HeroVired HeroVired HeroVired HeroVired HeroVired HeroVired HeroVired HeroVired HeroVired ...
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › difference-between-while-and-do-while
Difference Between While and Do While Loop in C, C++, & Java
February 5, 2026 - Want to know the distinctions between the while and the do while loop? While and do while loops are control structures that repeat a block of code until the given condition is true. This blog illustrates the Difference Between While and Do While Loop with syntax, comprehensive examples and flowcharts.
🌐
BYJUS
byjus.com › gate › difference-between-while-and-do-while-loop-in-c-c-plus-plus-java
Difference Between while and do-while loop in C, C++, Java
July 15, 2024 - The do-while loop is very similar to that of the while loop. But the only difference is that this loop checks for the conditions available after we check a statement. Thus, it is an example of a type of Exit Control Loop.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › difference between while and do-while loop
Difference between While and Do-While Loop - Shiksha Online
September 16, 2024 - Execution guarantee: Do-while guarantees at least one execution of the loop body, while a while loop may not execute at all. Condition placement: While checks before executing, do-while checks after executing.
🌐
W3Schools
w3schools.com › c › c_do_while_loop.php
C Do While Loop
The do/while loop always runs at least once, even if the condition is already false. This is different from a regular while loop, which would skip the loop entirely if the condition is false at the start.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › difference-between-while-loop-and-do-while-loop-in-programming
Difference between While Loop and Do While Loop in Programming - GeeksforGeeks
July 23, 2025 - These differences highlight the distinct characteristics of "while" and "do-while" loops in terms of their initial conditions and the guaranteed execution of the loop body.
🌐
Quora
quora.com › What-is-the-difference-between-do-and-while-loops-in-C-programming-language-Why-would-we-use-one-over-the-other-when-both-can-give-us-the-same-results
What is the difference between do and while loops in C programming language? Why would we use one over the other when both can give us the same results? - Quora
Answer (1 of 2): The difference between a “do…while” loop and a “while…” loop is that a do…while always runs the code body at least once…but a “while…” loop might exit without running the code body even once.
🌐
Quora
quora.com › What-is-the-difference-between-while-and-do-while-loops-in-C-programming-language-What-are-the-benefits-and-drawbacks-of-each-loop
What is the difference between 'while' and “do-while” loops in C programming language? What are the benefits and drawbacks of each loop? - Quora
Answer (1 of 5): hello, > What is the difference between "while" and “do-while” loops in C programming language? Do you know the cartoon "beep-beep and the coyote"? Beep-beep applies a while loop as it runs, in the form of [code]while (some_floor_for_next_step()) one_more_step(); [/code]w...
🌐
Quora
quora.com › What-is-the-difference-between-the-while-and-do-while-loop-in-C
What is the difference between the while and do while loop in C? - Quora
Answer (1 of 98): In while the given condition is checked at the start of the loop. If the condition is false then the loop is not executed at all. Only when the condition is true the loop block is executed. In do while first the loop block is executed then condition is checked at the end of ...
🌐
Sololearn
sololearn.com › en › Discuss › 2065905 › which-is-better-while-loop-or-do-while-loop-why-
Which is better ? While loop or do while loop. Why ? | Sololearn: Learn to code for FREE!
1 week ago - Printing a menu While makes sure ... because the do while is exit control loop its check the condition at the end of the loop and the while is entry control that's check the condition at the starting of the loop.....
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › difference-between-for-while-and-do-while-loop-in-programming
Difference between For, While and Do-While Loop in Programming - GeeksforGeeks
July 23, 2025 - For Loop, While Loop, and Do-While Loop are different loops in programming. A For loop is used when the number of iterations is known. A While loop runs as long as a condition is true.
🌐
Unstop
unstop.com › home › blog › do-while loop in c explained with code examples
Do-While Loop In C Explained With Detailed Code Examples
January 15, 2024 - A do-while loop in C is a post-tested control construct, which ensures that the code body is implemented at least once before the condition is checked. It simplifies input validation, ensures execution of the code at least once, and makes the ...