link in while loop

14 views
Skip to first unread message

Tomas Miklosovic

unread,
Jul 6, 2019, 3:21:07 PM7/6/19
to liam2-users
Hi, I would like to ask how I can change dummy variables in the while loop.
I have 40 dummy variables: dummy1q1, dummy1q2, dummy1q3, dummy1q4, dummy2q1, dummy1q2,.....dummy10q2, dummy10q3 and dummy10q4. I would like to change thier values in while loop. For example:
- i: i=1
- while i<=10:
     - j: j=1
     - while j<=4:
         - dummy[i]q[j]: if(condition, False, dummy[i]q[j])
         - j: j+1
     - i: i+1

Liam 2 say: SYNTAX ERROR: invalid syntax
where(condition, False, dummy[i]q[j])

How can I fix it ?

Thanks

Tomas M.

Gaëtan de Menten

unread,
Jul 19, 2019, 9:26:50 AM7/19/19
to liam2...@googlegroups.com

Sorry for the slow reply, I was on holidays.

 

The syntax error your are seeing as strictly speaking nothing to do with the while loop.

 

You can only have simple variables names as target of assignments, so "dummy[i]q[j]" is not a valid target.

 

The simplest way to fix this is to duplicate your "if" line 40 times:

    - dummy1q1: if(condition, False, dummy1q1)

    - dummy1q2: if(condition, False, dummy1q2)

    - dummy1q3: if(condition, False, dummy1q3)

    - dummy1q4: if(condition, False, dummy1q4)

    […]     

 

You could probably also solve this by storing all those dummy variables in an array created using array([False, False, etc.]), you could simply do:

- dummy: if(condition, False, dummy)

 

But then you would be entering undocumented territory so I wouldn't advise doing that unless you know what you are doing.

Gaëtan

 

--
You received this message because you are subscribed to the Google Groups "liam2-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liam2-users...@googlegroups.com.
To post to this group, send email to liam2...@googlegroups.com.
Visit this group at https://groups.google.com/group/liam2-users.
To view this discussion on the web, visit https://groups.google.com/d/msgid/liam2-users/8e9362d7-8c0f-4c39-a2b4-35a2170f841c%40googlegroups.com.



Disclaimer: This e-mail may contain confidential information which is intended only for the use of the recipient(s) named above.
If you have received this communication in error, please notify the sender immediately and delete this e-mail from your system.
Please note that e-mail messages cannot be considered as official information from the Federal Planning Bureau.

Tomas Miklosovic

unread,
Jul 26, 2019, 5:15:33 AM7/26/19
to liam2-users
Thank you for your answer.

But I looking for something more "effective".

It is possible add to LIAM2 functionality (in while loop) where would be possible doing with variables with numeric part? 
For example, as this command in python:

for k in range(5):
    exec(f'dummy{k} = 0')

After then it will be more efficiently doing with while loop (creating variables, changing variables or creating multiple csv output)

Thank you.

Tomas


Dňa piatok, 19. júla 2019 15:26:50 UTC+2 Gaëtan de Menten napísal(-a):

To unsubscribe from this group and stop receiving emails from it, send an email to liam2...@googlegroups.com.

Gaëtan de Menten

unread,
Jul 26, 2019, 10:07:53 AM7/26/19
to liam2...@googlegroups.com

Hi again,

 

Sorry, but the exec solution is not going to happen, probably ever. On the other hand, the array solution will happen one day. Technically, many of the pre-requisites for that feature (array fields) are already in place and the missing bits wouldn't be too hard to implement… BUT, given the very little time I spend on LIAM2 these days, that is not going to happen "soonish" unless we receive significant help or funding from another institution.

Gaëtan

 

To unsubscribe from this group and stop receiving emails from it, send an email to liam2-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/liam2-users/d4d9d778-e02a-4b97-aab3-7073821be379%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages