IF/THEN but also

Previous topic - Next topic

Wild_Duck

If I have multiple statements on the same line and the first IF/THEN is not true rather than go to the next line it caries on with the rest of the line.
eg.
x=x+1;IF x>100 THEN x=0; y=y+1
This will increment y every time through the loop instead of just when x=100

AndyH

Might not be a bug.  I think the ; is treated like a new line rather than the old BASIC : character, so that what you've really got is more like:

x=x+1
IF x>100 THEN x=0
y=y+1

That makes more readable sense.  I guess you must use IF ... ENDIF and that is more readable anyway.

bigsofty

Using an IF without ENDIF will only take the 1st command after the THEN statement, then carry on to the next line or the next ';' character.

The above execution is correct and its what I would expect to happen.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

No, you want this:
IF x>100
   x=0
   INC y,1
ENDIF