Retrieve IDs from custom field, count and display results differently according to count

I answer to myself, since this code is working better (previous had an issue) and also I removed a useless “for”:

echo '<ul class="related-content">';
$count = 0;
foreach(get_field('related_content') as $post_object) :
        $count++;
        if ($count > 0 && $count < 4 ) { 
            printf('<li class="large"><a target="_blank" title="'.get_the_title($post_object->ID).'" href="'.get_permalink($post_object->ID).'"><span style="display: block" title="'.get_the_title($post_object->ID).'">'.get_the_post_thumbnail($post_object->ID, 'small').'</span><span class="thumb-title">'.get_the_title($post_object->ID).'</span></a></li>');
            }
            elseif ($count > 3 && $count < 6 ) { 
                    printf('<li class="medium"><a target="_blank" href="'.get_permalink($post_object->ID).'">'.get_the_post_thumbnail($post_object->ID, 'smallest').'<span class="thumb-title">'.get_the_title($post_object->ID).'</span></a></li>');
            }
            elseif ($count > 6 ){ 
                    printf('<li class="small"><a target="_blank" href="'.get_permalink($post_object->ID).'"><span class="thumb-title">'.get_the_title($post_object->ID).'</span>'. get_field('title_subtitle').'</a></li>');
            }
            endforeach; 
            echo'</ul>';