PHP While Loop

PHP while loop executes a set of statements as long as a condition is true.

It requires relevant variables to be ready such as an indexing variable to iterate through a loop.


A while loop checks if the specified condition is true after each iteration. .


Glossary:

LoopIn computer programming, loops are instructions that repeat until a specified condition is reached.
IterationEach run or execution of the loop
<?php
$counter = 0;
while ($counter < 10)
{
	$counter += 1; // Increment By One
	echo "Executing - counter is $counter.\n"; // Print Outpur
}
?>

Explanation:

  1. Loop starts when the variable $counter is set to zero.
  2. For the first iteration of the loop, the variable $counter is incremented by one.
  3. For the second iteration of the loop, the variable $counter is incremented by one to become two.
  4. For the third iteration of the loop, the variable $counter is incremented by one to become three.
  5. For the fourth iteration of the loop, the variable $counter is incremented by one to become four.
  6. For the fifth iteration of the loop, the variable $counter is incremented by one to become five.
  7. For the sixth iteration of the loop, the variable $counter is incremented by one to become six.
  8. For the seventh iteration of the loop, the variable $counter is incremented by one to become seven.
  9. For the eighth iteration of the loop, the variable $counter is incremented by one to become eight.
  10. For the ninth iteration of the loop, the variable $counter is incremented by one to become nine.
  11. The tenth and final iteration of the loop, the variable $counter is incremented by one to become ten which is no less than the condition statement ($counter < 10).

This example above can be found in Learning PHP which is an online ebook. The only requirement is a web browser. You can use the built-in Web IDE to view your code and compile it online to view the result. You pay once for the online book and get access to the book at anytime without extra costs.


OjamboShop.com Learning PHP While Loop Example
OjamboShop.com Learning PHP While Loop Example

Limited Time Offer:

OjamboShop.com is offering 50% off coupon code VICTORIA for Learning PHP until Victoria Day 2024.


Conclusion:

Take this opportunity to learn PHP programming language by making a one-time purchase at Learning PHP. A web browser is the only thing needed to learn PHP in 2024 at your leisure. All the developer tools are provided right in your web browser.


References:

About Edward

Edward is a software engineer, web developer, and author dedicated to helping people achieve their personal and professional goals through actionable advice and real-world tools.

As the author of impactful books including Learning JavaScript, Learning Python, Learning PHP and Mastering Blender Python API, Edward writes with a focus on personal growth, entrepreneurship, and practical success strategies. His work is designed to guide, motivate, and empower.

In addition to writing, Edward offers professional "full-stack development," "database design," "1-on-1 tutoring," "consulting sessions,", tailored to help you take the next step. Whether you are launching a business, developing a brand, or leveling up your mindset, Edward will be there to support you.

Edward also offers online courses designed to deepen your learning and accelerate your progress. Explore the programming on languages like JavaScript, Python and PHP to find the perfect fit for your journey.

📖 Explore His Books – Visit the Book Shop to grab your copies today.
💼 Need Support? – Learn more about Services and the ways to benefit from his expertise.
🎓 Ready to Learn? – Check out his Online Courses to turn your ideas into results.