In the while statement, after while () inside the braket, the condition is given according to which the looping is to be done. If that condition is satisfied then the block of statements written after the while statement is executed. After that the while condition is checked again. If still that condition is fulfilled then the block of statements is executed again. This process continues as long as the condition of the while statement is satisfied.
Braket is used to write the block of statements of the loop. This braket should be used mainly when we have to use more than one statement inside the loop, but with caution if we are also using one statement inside the loop then also {} braces should be used.
while Statement
while (condition)
{
block of instructions
}
while स्टेटमेन्ट में while के बाद () braket के अन्दर वह शर्त दी जाती है, जिसके अनुसार लूपिंग की जानी है। यदि वह शर्त पूरी होती है तो while स्टेटमेन्ट के बाद लिखा गया block of statements execute होता है। उसके बाद पुनः while की शर्त को जाँचा जाता है। यदि अब भी वह शर्त पूर्ण होती है तो block of statements पुन execute होता है। यह प्रक्रिया जब तक चलती रहती है जब तक while स्टेटमेन्ट की शर्त पूर्ण होती रहती है। लूप के block of statements को लिखने के लिए braket का प्रयोग किया जाता है। यह braket मुख्यत तभी प्रयोग किए जाने चाहिए जब हमें लूप के अन्दर एक से ज्यादा स्टेटमेन्ट प्रयोग करने हों, परन्तु सावधानी वश यदि हम लूप के अन्दर एक स्टेटमेन्ट का भी प्रयोग कर रहे हैं तो भी {} braces का प्रयोग करना चाहिए।
Read More:
while स्टेटमेन्ट
while स्टेटमेन्ट का सूत्र-
while (condition)
{
block of instructions
}