while loop use in Laravel Blade file with Example

Laravel blade while loop; In this tutorial we will show you how to use the while loop in laravel blade file with example. You will learn a simple way how to do it and apply it to your Laravel 9 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 checks the condition first. If it evaluates to true, the block of code is executed as long as the condition is true. If it evaluates to false, the execution of the while loop is terminated.

Syntax:

Laravel Blade While Loop Syntax

@while (condition)
    //block of code to be executed;
@endwhile

Example:

Laravel Blade While Loop Example

<!DOCTYPE html>
<html>
<head>
    <title>Laravel Blade While Loop Example</title>
</head>
<body>
    @while ($user->id < 2)
        //The user id is less then two;
    @endwhile
</body>
</html>

I hope this example help you..

Leave a Comment