BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: If Statement
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

If Statement

 Post Reply Post Reply
Author
Message Reverse Sort Order / View First Unread Post
NeilW View Drop Down
Newbie
Newbie


Joined: 06 Aug 2006
Location: Australia
Posts: 8
Post Options Post Options   Quote NeilW Quote  Post ReplyReply Direct Link To This Post Topic: If Statement
    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
Back to Top
zorro View Drop Down
Newbie
Newbie
Avatar

Joined: 17 Apr 2005
Posts: 17
Post Options Post Options   Quote zorro Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
scrooge View Drop Down
Newbie
Newbie


Joined: 27 Jun 2006
Posts: 13
Post Options Post Options   Quote scrooge Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
NeilW View Drop Down
Newbie
Newbie


Joined: 06 Aug 2006
Location: Australia
Posts: 8
Post Options Post Options   Quote NeilW Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
chart rider View Drop Down
Regular
Regular
Avatar

Joined: 25 Sep 2004
Location: Australia
Posts: 96
Post Options Post Options   Quote chart rider Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
NeilW View Drop Down
Newbie
Newbie


Joined: 06 Aug 2006
Location: Australia
Posts: 8
Post Options Post Options   Quote NeilW Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz