Author Topic: := not working as thought  (Read 2315 times)

0 Members and 1 Guest are viewing this topic.

kryton9

  • Guest
:= not working as thought
« on: June 27, 2011, 07:37:59 PM »
Code: Text
  1. 'Error when using := with if statements. I thought we were supposed to use them with those?
  2.  
  3. 'this part works
  4. int x, y
  5. y = 0
  6. string s = ""
  7.  
  8. for x = 1 to 25
  9.     y++
  10.     if y = 20 then
  11.         y = 0
  12.     end if
  13.     s+= "x " x  "     y " y chr(10) chr(13)
  14. next
  15.  
  16. print s
  17.  
  18.  
  19. 'this doesn't work
  20. quad i, j
  21. j = 0
  22. s = ""
  23.  
  24. for i = 1 to 25
  25.     j++
  26.     if j := 20 then
  27.         j = 0
  28.     end if
  29.     s += "i " i  "     j " j chr(10) chr(13)
  30. next
  31.  
  32. print s
  33.  
  34.  
  35. 'this works
  36. j = 0
  37. s = ""
  38.  
  39. for i = 1 to 25
  40.     j++
  41.     if j = 20 then
  42.         j = 0
  43.     end if
  44.     s += "i " i  "     j " j chr(10) chr(13)
  45. next
  46.  
  47. print s

Charles Pegge

  • Guest
Re: := not working as thought
« Reply #1 on: June 27, 2011, 08:58:23 PM »
it assigns the value of right hand expression to j then  makes a zero / nonzero evaluation on the right hand expression and procedes if non zero.


if j := 20

Charles

PS I see there is a problem with assigning to quads in this way
« Last Edit: June 27, 2011, 09:23:32 PM by Charles Pegge »