for loop error

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

leah
Posts: 35
Joined: Tue Jul 16, 2013 2:29 pm

for loop error

Postby leah » Wed Jul 17, 2013 10:43 am

Hi there! So I'm trying to create a shell program that will take a list of databases and use them in a series of programs. However, when I run it I get the error, "Next found outside of loop or IF statement." The wierd thing is, when I comment out three of the included programs, it runs until it gets an error related to the programs not being included. If I include just one of those problem programs, I'll get the same error again.

I've gone through those three programs and there are no "nexts" without matching "fors". In the actual program, I also have statements before the next that close the databases, etc. that I have opened, but they don't seem to affect anything. Any thoughts on what could be causing this error? Thanks in advance for your help.

%files = @wdir("P:\Growth\Policy\2013_Immigration_Analysis\Output\CGE")
%files = @wkeep(%files, "*hi.edb *md.edb *lo.edb")

for !i=1 to @wcount(%files)

wfcreate(wf=smallbudmod!i,page=annual) a 2004 2023
%begdat = "2006"
%enddat = "2023"

pagecreate(page=quarterly) q %begdat %enddat
pageselect quarterly
smpl %begdat %enddat

'Open the black box
dbopen p:\bbox\final\2013_1\b130114b.edb as rec

'Change working directory to the specified folder
cd "P:\Growth\Policy\2013_Immigration_Analysis\Output\CGE\"

%db = @word(%filenames,!i)
dbopen %db as recnew

include u:\SBM\dataprep.prg
include u:\SBM\snapacaid.prg
include u:\SBM\badmodelui.prg
include u:\SBM\tadmodel.prg
include u:\SBM\badmodel.prg
include u:\SBM\eitc&doccare.prg

next

leah
Posts: 35
Joined: Tue Jul 16, 2013 2:29 pm

Re: for loop error

Postby leah » Wed Jul 17, 2013 10:45 am

And this is in EViews 7.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: for loop error

Postby EViews Gareth » Wed Jul 17, 2013 11:00 am

You can't really use an include inside a loop. Use Exec instead.

leah
Posts: 35
Joined: Tue Jul 16, 2013 2:29 pm

Re: for loop error

Postby leah » Wed Jul 17, 2013 11:27 am

That solved it, thank you. Out of curiosity, why is that?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: for loop error

Postby EViews Gareth » Wed Jul 17, 2013 1:31 pm

Include simply does an in place copy and paste of the included file into the source file. When inside a for-loop the technology that performs that copy and paste sort of fails.

Also you cannot include a program more than once. Although you've only included it once, inside a for loop you're sort of including it more than once.

Includes are really meant for "library" like programs that would simply contain sub-routines that would be called by the parent program. They're not really meant for executing raw code (which is why we introduced the Exec command).


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest