Why doesn’t ‘continue’ work in page?

get_the_terms returns an array of terms – so $terms is an array.

Therefore, your condition:

if( $terms->slug != 'product-gallery' )

will always return false, and therefore skip every post every time.

Try

if ( in_array( 'product-gallery', $terms ) ) continue;

The above is untested.

error code: 523