There is no loop in the code that you provided. What you provided only determines that the modal should appear on the current page that is being viewed.
....
in_array($id, $spm_display_ids)
...
the current page $id
is in the array of pages that it should be shown on $spm_display_ids
If this is true then this line is run
@include('specials-modal')
Exactly what is shown is determined by whatever that includes.