Table of contents
In this post, I will share a basic example of a while loop in Laravel blade. I will show you how to implement a while loop in the Laravel 8 blade. You will learn a simple way how to do it and apply it to your Laravel 8 project.
Â
The while loop checks the condition first if true then the code it will be executed. If evaluated to false, the execution will be terminated.
Â
The while loop iteration value of the current array element is assigned to $value and the array pointer is moved by one until reaches the last array element.
Â
Laravel Blade While Loop Syntax:
@while (condition)
//block of code to be executed;
@endwhile
Â
Laravel Blade While Loop Example:
<!DOCTYPE html>
<html>
<head>
<title>Laravel 8 Blade While Loop Example</title>
</head>
<body>
@while ($id < 10)
//The id is less then 10;
@endwhile
</body>
</html>
Â
Read next