C do...while Loop

You are Here:

C do...while Loop

The do while loop executes a specified statement until the test condition evaluates to false.

Note: Unlike while loop, In do...while loop, the condition is evaluated after executing the statement, resulting in the specified statement executing at least once.

Syntax

do{ // code block }while(condition);

Simple do...while Loop

In the following program, we will print 'Hello World' for 5 times using do...while loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; do{ printf("Hello World \n"); i++; }while(i<5); return 0; }

Output

Hello World Hello World Hello World Hello World Hello World

do...while Loop to print numbers

In the following program, we will print numbers from 0 to 4 using do...while loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; do{ printf("%d ",i); i++; }while(i<5); return 0; }

Output

0 1 2 3 4

do...while Loop to print Elements in a Array

In the following program, we will print all the elements in an array using do...while loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; char absent[3] = {13, 25, 36}; printf("Absent Roll No's are: "); do{ printf("%d ", absent[i]); i++; }while(i<3); return 0; }

Output

Absent Roll No's are: 13 25 36

do...while Loop to print Array of Strings

In the following program, we will print the array of strings using do...while loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; char students[3][6] ={"gouri", "ram","alex"}; do{ printf("%s \n", students[i]); i++; }while(i<3); return 0; }

Output

gouri ram alex
congratulation

Congratulation! you have learned everything about do...while statement in C Programming.

Reminder

Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author