Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

10. Looping Statements

Lesson 11 of 36 in the free Web Based Programming notes on Siksha Sarovar, written by Rohit Jangra.

3. Looping Statements in PHP

Loops are used to execute a block of code repeatedly.

3.1 for Loop Used when the number of iterations is known.

        for ($i = 1; $i <= 5; $i++) {
          echo $i . "<br>";
        }

3.2 while Loop Executes code while condition is true.

        $i = 1;
        while ($i <= 5) {
          echo $i . "<br>";
          $i++;
        }

3.3 do–while Loop Executes code at least once, even if condition is false.

        $i = 1;
        do {
          echo $i . "<br>";
          $i++;
        } while ($i <= 5);

3.4 foreach Loop Used to iterate through arrays.

        $subjects = array("HTML", "CSS", "PHP");
        foreach ($subjects as $sub) {
          echo $sub . "<br>";
        }

4. Comparison of Loops

LoopUse Case
forKnown number of iterations
whileUnknown iterations
do-whileExecute at least once
foreachArrays

5. Comparison of Conditional vs Loop Statements

FeatureConditionalLoop
PurposeDecision makingRepetition
ExecutesBased on conditionMultiple times
Examplesif, switchfor, while