Q:

i want to add a statement in blade @foreach loop

I am new in Laravel and I  want to add "," and "and" statement in between these two outputs, depending on how many speakers there is. But when I add this statement it loops.
So the "and" statement should go before the last. And I want to point out that it outputs first name separately than the last name.
<div class="col-md-6">
 <h3>

  @foreach($lecture->speakers as $speaker)
  <b>{{$speaker->first_name}}{{$speaker->last_name}}</b>
  @endforeach

 </h3>                    
<div>

Would be grateful if someone could help me!

A:

Try something like this:
@for ($i = 0; $i < count($lecture->speakers); $i++)
    <b>{{ $lecture->$speakers[$i]->first_name}}{{ $lecture->$speakers[$i]->last_name}}</b>
    @if ($i < (count($lecture->speakers) - 2))
        and
    @elseif ($i === (count($lecture->speakers) - 2))
        ,
    @endif
@endfor

Well, I hope you got the idea, play with this code and I think it will work for you.

