In my opinion we cannot guarantee the post existence in db for a specific query. maybe it returns an empty array. so its best practice to use the conditional statement. plus i think we are dealing with an array so to check the empty array we should use php empty
function.
for example:
if ( !empty( $attachments ) ) {
foreach ( $attachments as $attachment ) {
// do some stuff here.
}
}
else {
_e('Sorry! No posts found.');
}