If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Actually किसी code of block को repeatedly run करने का सबसे easy way looping है , PHP में different - different Looping Statements हैं -
इस Topic में हम while Loop के बारे में पढ़ेंगे
PHP में While Loop ठीक वैसे ही काम करते हैं जिस तरह से C या JAVA में करते हैं। While Loop Simply Nested Statements को Execute करता है , जब तक कि दी हुई Condition False न हो। जब तक Condition True है तब तक Loop Execute होगा। While Loop को Entry Control Loop भी कहते हैं क्योंकि loop को Execute करने से पहले दी हुई condition Check होती है , condition True होने पर ही Loop में Entry होती है।
while(condition / expression) { //write your logic }
File : while.php
<?php
/*Example 1 to print print 1 to 10*/
$x = 1;
while ($x <= 10)
{
echo $x.", ";
/*increment by 1*/
++$x;
}
/*break the line*/
echo "<br>";
/*Example 2 to print print 1 to 10*/
$x = 1;
while ($x <= 10) :
echo $x.", ";
/*increment by 1*/
++$x;
endwhile;
?>
चूंकि मैं पहले भी बता चुका हूँ कि PHP में हम colon (:) का use भी कर सकते हैं इसलिए ऊपर दिए गए example में दो बार 1 से 10 तक print हुआ।
इसके अलावा आप PHP में Nested While Loop का भी use कर सकते हैं , means While Loop के अंदर एक और While Loop.
Example -
File : nested_while.php
<?php
$x = 1;
while($x <= 10)
{
$y = 1;
echo $y." ";
while($y < $x)
{
$y++;
echo $y." ";
}
++$x;
echo"<br>";
}
?>
I hope अब आप While Loop और Nested While Loop के बारे में अच्छी तरह से समझ गए होंगे।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook