How to loop over strings, or specific numbers

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
cap
Posts: 11
Joined: Thu Aug 14, 2008 2:32 pm

How to loop over strings, or specific numbers

Unread post by cap »

Hello,

I'd like to create a do loop where the index variable takes on the values of certain strings, or certain numbers, such as the following (which of course doesn't actually work):

--------------------------------
do i="aaa" "bbb" "ccc"

disp i

end do i
-------------------------------
or like this,
--------------------------------
do i = 2,18,23

disp i

end do i
----------------------------------




Thanks in advance,


CP
cap
Posts: 11
Joined: Thu Aug 14, 2008 2:32 pm

Unread post by cap »

Nevermind, I got it.



declare vector[integer] myvec(3)

compute myvec(1)=7
compute myvec(2)=20
compute myvec(3)=21


dofor i=myvec
disp i
end dofor




declare string mystr

dofor mystr= "aaa" "bbb" "ccc"

disp mystr

end dofor
Post Reply