If Statement |
Post Reply |
Author | |
NeilW
Newbie Joined: 06 Aug 2006 Location: Australia Posts: 8 |
Post Options
Quote Reply
Topic: If Statement Posted: 15 Aug 2006 at 9:23pm |
Hi All, How exactly does the If statement work? a := 1; b := 2; c := 3; If I were to use the following If(A<>B,C=A,C=B); What does C now hold? From testing the 2nd & 3rd arguments are purley assignments not areas were code can be placed. I.e. C=A If(A<>B,"A","B"); In this case here "A" will be printed. Neil.
Edited by NeilW |
|
chart rider
Regular Joined: 25 Sep 2004 Location: Australia Posts: 96 |
Post Options Quote Reply Posted: 17 Aug 2006 at 6:29pm |
Neil You appear to have answered your question? The 2nd argument is the result if the 1st code is true, while the 3rd assignment is the result if the 1st code is false. CR |
|
NeilW
Newbie Joined: 06 Aug 2006 Location: Australia Posts: 8 |
Post Options Quote Reply Posted: 18 Aug 2006 at 5:46pm |
Hi, Yes and no, what is the value of C in the first question? If I have A:=4 A=5 A=6 A=7 Now what is the value of A? It is 4 so with the following K:=4 if(true,K=5,K=6) would you expect K to now equal 4 or 5? My testing shows K=4 You can only assign a variable once and it almost appears that the k=5 in the above IF is not an assigment but a comparison. if you try the following K:=4 if(true,k:=5,K:=6) you get syntax error messages.
Neil. |
|
scrooge
Newbie Joined: 27 Jun 2006 Posts: 13 |
Post Options Quote Reply Posted: 22 Aug 2006 at 12:00pm |
I think you are correct that = leads to a comparison not an
assignment. Therefore the expression If(A<>B,C=A,C=B)
will return false if A<>B and C<>A, true if A<>B and
C=A and so on.
To assign a value to C try this: C:= if(A<>B,A,B) |
|
zorro
Newbie Joined: 17 Apr 2005 Posts: 17 |
Post Options Quote Reply Posted: 29 Aug 2006 at 9:01pm |
Yes, this is correct.
= is a comparison, and will return either 1 or zero depending on whether the two variables are the same, but it doesn't actually store anything in either variable. Whereas := is an assignment. Though they both look similar, they're very different in what they do. Each variable can only be assigned to once. |
|
NeilW
Newbie Joined: 06 Aug 2006 Location: Australia Posts: 8 |
Post Options Quote Reply Posted: 29 Aug 2006 at 9:16pm |
Hi Zorro, Your last statement was in reality the final answer. "Each variable can only be assigned to once. " I have not found in the Help where this is actually stated, perhaps some more generalised syntax help would not go astray. I personally program in Pascal as well as C and I'm aware of the differances between a comparison and a asssignment. Both of the above languages are different in these areas. It was in Bullcharts scripting language, that allowed me to appear to do some assigning and also the gotcha of only being aloud to assign a variables once that caught me. This once only assigmnet I find to be a pain in the <bleep> Just out of interest, I wonder what the result of A is - A := If(1=2,3=3,4=4); Does A = True ?? Neil. Edited by NeilW |
|
Post Reply |
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |