If you used a variable of integer instead of
while(1) like while(not_reached_border)
then when your x position reaches your req x position set not_reached_border to 1..
Why would you do this? 'while' is a comparison.
while(pan->pos_x < screen_size.x- bmap_width(pan->bmap)){ ...code...
wait(1);}
.. then restore pan->pos_x to your save starting points...
Why create variable?