In Laravel, Blade's control structures like @foreach, @for, @while, and @switch provide a convenient way to loop through data, iterate over a set number of times, execute code while a condition is true, or switch between different cases. Here's how you can use these control structures:
@foreach($array as $item)
// code to be executed for each $item
@endforeach
You can also access the index using $loop variable:
@foreach($array as $item)
{{ $loop->index }}: {{ $item }}
@endforeach
@for($i = 0; $i < 5; $i++)
// code to be executed for each iteration
@endfor
@while($condition)
// code to be executed while $condition is true
@endwhile
@switch($variable)
@case('value1')
// code to be executed if $variable equals 'value1'
@break
@case('value2')
// code to be executed if $variable equals 'value2'
@break
@default
// code to be executed if $variable doesn't match any cases
@endswitch
These control structures can be used within your Laravel Blade templates to handle complex logic, iterate through data, and execute code based on certain conditions. Remember to use the correct syntax and properly close the control structure using the respective ending directive.