This statement is also a conditional branching process. It is used exactly like while statement. The main difference is that in the while statement, the condition is checked first and the block is executed only after the condition is met, but in the do statement, the block is executed first and then the condition is checked. If the condition is met then the block is executed for the second time. This process continues as long as the condition is not met.
Special - The block written in the do statement must be executed at least once. Whereas in other looping statement, the execution of the block depends on the fulfillment of the condition.
Formula of do statement-
do
}
Block of Instruction
}
while(condition);
In this also {} braces are used to write more than one statement inside the loop.
यह स्टेटमेन्ट भी सशर्त ब्रान्चिग प्रक्रिया है। इसे बिल्कुल while स्टेटमेन्ट की भाँति प्रयोग किया जाता है। इसमें मुख्य अन्तर है कि while स्टेटमेन्ट में शर्त पहले चैक होती है और शर्त के पूर्ण होने पर ही block execute होता है लेकिन do स्टेटमेन्ट में प्रथम द्वार block execute हो जाता है फिर शर्त को चैक किया जाता है। यदि शर्त पूर्ण होती है तो block दूसरी बार execute हो जाता है। यह प्रक्रिया जब तक चलती रहती है, जब तक शर्त अपूर्ण नहीं होती।
Read more:
विशेष- do स्टेटमेन्ट में लिखा गया block कम से कम एक बार execute अवश्य होता है। जबकि अन्य लूपिंग स्टेटमेन्ट में block का execute होना शर्त के पूर्ण होने पर निर्भर करता है।
do स्टेटमेन्ट का सूत्र-
do
}
Block of Instruction
}
while (condition);
इसमे भी एक से ज्यादा स्टेटमेन्ट को लूप के अन्दर लिखने के लिए {} braces का प्रयोग किया जाता है।