while loop - Tech S K

Latest

Notes of Computers Technology Information,Latest Tech News, O Level Software Notes,RS CIT notes The notes of all the computer's exams are available here

Recent Posts

Translate

बुधवार, 13 जून 2018

while loop

आज Hindi के इस C/C++ programming language tutorial को आगे बढ़ाते हुए हम while loop का उपयोग करना सीखेंगे. इसमें एक boolean statement दिया जाता है. जब तक उसकी value true आती है तब तक loop के अंदर लिखे statement run होते रहते हैं. जब तक  नीचे दिए गए example से समझते हैं. while loop का उपयोग करके एक बार फिर से 1 से 10 तक कि संख्याओ के square print करेंगे
#include <stdio.h>

int main() {
int i=1;
int sq;
while(i<=10) {
sq = i*i;
printf("square of %d is %d.\n", i, sq);
i = i+1;
}

scanf("%d", &i);
return 1;
}

ऊपर दिए गए program में i की प्रारंभिक  value 1  है. उसके बाद while loop का boolean statement है i<=10 जो कि true  है क्योंकि i की value 1 है, इसलिए loop के अंदर लिखे सारे statement execute हो जायेंगे. ध्यान दें कि हम loop के अंदर i की value 1 बढ़ा रहे हैं. फिर से boolean statement true  हो जायेगा क्योंकि i की  value 2 हो गयी है. इसी तरह आगे बढते रहेंगे. जब i की value 11 हो जायेगी तब boolean statement false हो जाएगा और हम while loop से बाहर आ जायेंगे. इस program को चला कर देखें. यह 1 से 10 तक सभी संख्याओ के square print करेगा.

अगले लेख में हम string का उपयोग करना सीखेंगे और साथ ही उसका use करके कुछ interesting example देखेंगे.

कोई टिप्पणी नहीं:

एक टिप्पणी भेजें

Friends, if you like this post then please share it on Facebook! Please tell through the comments that these posts will welcome you as well as your suggestions.