IF THEN ELSE Qns

Use this forum to post Vensim related questions.
Post Reply
Seikyo
Junior Member
Posts: 7
Joined: Fri Jun 16, 2006 7:27 am

IF THEN ELSE Qns

Post by Seikyo »

Just wondering, how do we formulate a double IF THEN ELSE condition? For example,

Before time x, the value is x,
After time x, the value is STEP(y,<Time X>),
Then after time z, the value is change to STEP(z, <time z>)

is it possible to write equation like other programming language

IF <Condition> Then <Value X>

IF <Condition> Then <Value Y>

Else <Value Z>
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

You can nest IF THEN ELSE statements, but it does make the equations harder to read (I try to avoid them unless it is absolutly necessary).

IF THEN ELSE ( time < A
, condition A
, IF THEN ELSE ( time < B
, condition B
, condition C )
)

Tony.
Seikyo
Junior Member
Posts: 7
Joined: Fri Jun 16, 2006 7:27 am

Post by Seikyo »

Thanks. That is the syntax I am looking for. I am still figuring out ways to avoid it.
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

nested if then else

Post by LAUJJL »

Hi
To avoid the syntax, the solution is to use intermediary variables.
If then else (A < B,C,D),
D = if then esle (X >Y,E,F)
It reduces the complexity of the equations but increases the
complexity of the sketch.
Regards.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

If I cannot avoid nesting IF THEN ELSE, I do something like the following.

Some result =
IF THEN ELSE ( time < A , condition A , 0 )
+ IF THEN ELSE ( time >= A :AND: time < B , condition B , 0 )
+ IF THEN ELSE ( time >= B :AND: time < C , condition C , 0 )
+ IF THEN ELSE ( time >= C :AND: time < D , condition C , 0 )

As long as you are careful and make sure each condition can only happen by itself, it makes things a little easier to read. It does for me anyway.

Tony.
rdudley
Senior Member
Posts: 71
Joined: Mon Sep 08, 2003 2:16 am

Post by rdudley »

But I think that the point is not only to avoid _nesting_ If then else statememts, but to avoid USING them in the first place.

If you have lots of if then else statements you should probably think about using a different modeling approach.

I normally use them only to turn on or off effects from selected parts of the model.
R. G. Dudley
Post Reply