do while Vs while loop in C Programing?

(Last Updated On: April 9, 2017)

Answer: Difference between do while and while loop: do…while loop guaranteed to execute at least one time whereas while loop does not.

All statements within do…while loop get executed first and then while condition is checked. Hence, it executes at least one time.

In below example, “interviewsansar.com” will be printed once using do…while loop whereas using while it will not print.

 

 

NOTES: We use do…while loop where we need to execute a piece of code once and on the basis of that execution we decide whether to execute that code repeatedly or not. In this case while or for loop does not work.