Page 1 of 1

Control Variables already defined in nested FOR loop

Posted: Wed Oct 30, 2013 3:32 am
by Dave_the_Forecaster
Hi, sorry if someone has posted a topic about this already. I've written the following loop:

Code: Select all

%series_list = "econ1 econ2 econ3" For %portfolio port1 port2 port3 For %model test1 test2 test3 test4 %temp= "%" + %portfolio + "_" + %model wfopen {%temp} %current_wf1=@wfname For %series {%series_list} Pageselect New_Port if @isobject(%series)=1 then copy(overwrite) {%current_wf1}::New_Port\{%series} {%wf1_name}::Economics\{%series}_{%portfolio}_{%model} else statusline %series does not exist in workfile %temp endif next wfuse {%current_wf1} wfclose next next
where port1_test1 etc are pre-defined string variables containing the file name and path of previously saved workfiles.

The problem I'm having is that when the code runs the final iteration of the 3rd loop, it tries to run it again, replacing the control variable %series with econ3 and so the program falls over.

I've tried resetting %series="" at the end of the loop but that causes a similar error.

Hope I've explained my problem well. Any ideas??

Re: Control Variables already defined in nested FOR loop

Posted: Wed Oct 30, 2013 8:12 am
by EViews Gareth
I cannot see anything particularly wrong with the loop structure. Indeed a simple test of the loop structure seems to indicate it is fine:

Code: Select all

create u 10 table a !i = 1 %series_list = "econ1 econ2 econ3" For %portfolio port1 port2 port3 For %model test1 test2 test3 test4 %temp= "%" + %portfolio + "_" + %model For %series {%series_list} a(!i,1) = %portfolio a(!i,2) = %model a(!i,3) = %series !i = !i+1 next next next