Do While Loop - PHP - P30
A regular while loop will skip over the loop body if the expression that’s evaluated is never true. But what if we need the contents of the body to be executed at least once? That’s what the do-while loop does for us.
$will_execute = false;
while ( $will_execute ) {
echo "I will execute at least once";
}
Looking at the code above, the while loop will never execute since the expression is always false. PHP will just skip over it. In this example, we want the statement to execute at least once. We want PHP to display “I will execute at least once” regardless of whether the expression evaluates to true or not.
As a recap, the way that the while loop is processed is as follows:
- PHP tests the expression inside of the while loop.
- If true, execute the code inside of the loop body. Go back to 1 and repeat.
- If false, exit the loop and continue code execution after the loop’s closing curly brace.
The do-while loop flips 1 and 2. It starts by executing the content inside of the loop body and then tests the condition. Even if the condition is false, the code inside of the loop body has already been executed once. If the condition is true, it executes the content inside of the loop body again and keeps repeating the process until the loop expression is evaluated to false.
The do-while loop has the following structure:
do {
code to execute
} while ( expression );
Read the full article on my website
https://www.dinocajic.com/php-do-while-loop/
Code for this tutorial
https://github.com/dinocajic/php-7-youtube-tutorials/blob/master/30%20Do%20While.php
Full Code
https://github.com/dinocajic/php-7-youtube-tutorials
PHP Playlist
https://www.youtube.com/playlist?list=PLbhJy0VhR6SAmoneYvF6Y_axQJKg7i50M
--
Dino Cajic
Author and Head of IT
Homepage: https://www.dinocajic.com
GitHub: https://github.com/dinocajic
Medium: https://medium.com/@dinocajic
Instagram: https://www.instagram.com/think.dino
LinkedIn: https://www.linkedin.com/in/dinocajic/
Twitter: https://twitter.com/dino_cajic
My Books
An Illustrative Introduction to Algorithms
https://www.amazon.com/dp/1686863268
Laravel Excel: Using Laravel to Import Data
https://amzn.to/4925ylw
Code Along With Me - PHP: From Basic to Advanced PHP Techniques
https://amzn.to/3M6tlGN
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Do While Loop - PHP - P30», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.