Contents
show
while loop in C Language in Hindi
जबकि लूप को प्री-टेस्टेड लूप के रूप में भी जाना जाता है। सामान्य तौर पर, एक लूप लूप बूलियन स्थिति के आधार पर कई बार कोड के एक हिस्से को निष्पादित करने की अनुमति देता है। यदि इसे statement के रूप में दोहराया जा सकता है। जबकि लूप का उपयोग ज्यादातर उस मामले में किया जाता है जहां पुनरावृत्तियों की संख्या पहले से ज्ञात नहीं है।
Syntax of while loop in C language
C भाषा में लूप के सिंटैक्स को नीचे दिया गया है:
Example of the while loop in C language
आइए while लूप के सरल प्रोग्राम को देखते हैं जो 1 की तालिका को प्रिंट करता है।
-
#include<stdio.h>
int main(){
int i=1;
while(i<=10){
printf("%d \n",i);
i++;
}
return 0;
}
Output
1 2 3 4 5 6 7 8 9 10
Program to print table for the given number using while loop in C
#include<stdio.h>
int main(){
int i=1,number=0,b=9;
printf("Enter a number: ");
scanf("%d",&number);
while(i<=10){
printf("%d \n",(number*i));
i++;
}
return 0;
}
Output
Enter a number: 50 50 100 150 200 250 300 350 400 450 500
Enter a number: 100 100 200 300 400 500 600 700 800 900 1000
Properties of while loop
- एक conditional expression का उपयोग स्थिति की जांच करने के लिए किया जाता है। दिए गए शर्त के विफल होने तक लूप के अंदर परिभाषित statement बार-बार निष्पादित होंगे।
- यह condition true होगी यदि यह वापस लौटाता है 0. यह condition false होगी यदि यह किसी गैर-शून्य संख्या को वापस करता है।
- while loop में, condition की expression अनिवार्य है।
- body के बिना while लूप चलाना संभव है।
- while loop में हमारे पास एक से अधिक conditional expression हो सकती है।
- यदि लूप बॉडी में केवल एक statement होता है, तो braces optional होते हैं।
Example 1
#include<stdio.h>
void main ()
{
int j = 1;
while(j+=2,j<=10)
{
printf("%d ",j);
}
printf("%d",j);
}
Output
3 5 7 9 11
Example 2
#include<stdio.h>
void main ()
{
while()
{
printf("hello Javatpoint");
}
}
Output
compile time error: while loop can't be empty
Example 3
#include<stdio.h>
void main ()
{
int x = 10, y = 2;
while(x+y-1)
{
printf("%d %d",x--,y--);
}
}
Output
infinite loop
Infinitive while loop in C
यदि लूप में बीतने पर अभिव्यक्ति किसी भी गैर-शून्य मान में होती है, तो लूप अनंत बार चलेगा।
while(1){
//statement
}