This is my second PIC program, and I am having a problem. The IF - THEN statements look OK to me, but the compiler doesn't like it.

'device: 16F627A
S3 var portb.1 ' S3 is the timer output
S4 var portb.2 ' S4 determins whether short time or
' long time is measured. 0=short, 1=long
T var byte

green var portb.4 'Drives the green LED (physical pin 10)
red var portb.5 'Drives the red led (physical pin 11)
input s3
input s4
high green : high red 'LEDs are initally off
loop:
if s3=1 then time
goto loop

time:
if S4=0 then t =500 : endif
if s4 =1 then t = 5000 : endif
pause t
if t = 500 and s3 = 1 then bad : endif
if t = 500 and s3 = 0 then good : endif
* if t = 5000 and s3 = 0 then bad : endif
if t = 5000 and s3 = 1 then good :endif
stop ' should never get here!

In the line with the *, the compiler says that "then" is missing. Why does it not see it? the compiler does not like any of the IF - THEN statements. I did not use "endif" originally but got an error " endif missing".