Contents
show
do while loop in C Language in Hindi
do while loop एक post tested loop है। do while loop का उपयोग करके, हम statements के कई हिस्सों के execution को दोहरा सकते हैं। do while loop का उपयोग मुख्य रूप से उस मामले में किया जाता है, जहां हमें कम से कम एक बार loop execute करने की आवश्यकता होती है। do while loop का उपयोग ज्यादातर menu driven programs में किया जाता है, जहां समाप्ति (termination) की condition end user पर निर्भर करती है।
do while loop syntax
C भाषा का सिंटैक्स, जबकि लूप नीचे दिया गया है:
do{
//code to be executed
}while(condition);
Example 1
#include<stdio.h>
#include<stdlib.h>
void main ()
{
char c;
int choice,dummy;
do{
printf("\n1. Print Hello\n2. Print hinditutorialspoint\n3. Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1 :
printf("Hello");
break;
case 2:
printf("hinditutorialspoint");
break;
case 3:
exit(0);
break;
default:
printf("please enter valid choice");
}
printf("do you want to enter more?");
scanf("%d",&dummy);
scanf("%c",&c);
}while(c=='y');
}
Output
1. Print Hello 2. Print hinditutorialspoint 3. Exit 1 Hello do you want to enter more? y 1. Print Hello 2. Print hinditutorialspoint 3. Exit 2 hinditutorialspoint do you want to enter more? n
Flowchart of do while loop
do while example
वहाँ सी भाषा का सरल कार्यक्रम दिया जाता है, जबकि लूप जहां हम 1 की तालिका को प्रिंट कर रहे हैं।
-
#include<stdio.h>
int main(){
int i=1;
do{
printf("%d \n",i);
i++;
}while(i<=10);
return 0;
}
Output
1 2 3 4 5 6 7 8 9 10
Program to print table for the given number using do while loop
#include<stdio.h>
int main(){
int i=1,number=0;
printf("Enter a number: ");
scanf("%d",&number);
do{
printf("%d \n",(number*i));
i++;
}while(i<=10);
return 0;
}
Output
Enter a number: 5 5 10 15 20 25 30 35 40 45 50
Enter a number: 10 10 20 30 40 50 60 70 80 90 100
Infinitive do while loop
यदि हम सशर्त अभिव्यक्ति के रूप में किसी भी गैर-शून्य मान से गुजरते हैं तो डू-लूप अनंत बार चलेगा।
do{
//statement
}while(1);