Author Topic: IF/THEN but also  (Read 3043 times)

Offline Wild_Duck

  • Mc. Print
  • *
  • Posts: 15
  • Mo and Me
    • View Profile
IF/THEN but also
« on: 2008-Jan-11 »
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

Offline AndyH

  • Dr. Type
  • ****
  • Posts: 383
    • View Profile
    • http://www.ovine.net/
IF/THEN but also
« Reply #1 on: 2008-Jan-11 »
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.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2702
    • View Profile
IF/THEN but also
« Reply #2 on: 2008-Jan-11 »
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)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10760
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
IF/THEN but also
« Reply #3 on: 2008-Jan-11 »
No, you want this:
IF x>100
   x=0
   INC y,1
ENDIF