Yep, that'll work.
That's the older pBasic style, so it's demonstrating one way to work around not having an if-then-else statement. There are several ways to do it. This is a shorter way to do the same thing:
Code:
PWM2 = p1_y
if relay2_fwd = 1 then next1:
PWM2 = 127
next1: