Re: Lists and Loops
- To: mathgroup at smc.vnet.net
- Subject: [mg113015] Re: Lists and Loops
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Mon, 11 Oct 2010 05:15:50 -0400 (EDT)
- References: <i8s5e7$935$1@smc.vnet.net>
Hi Michaell,
You forgot to end each line in the loop with a semicolon. Stuff you
put into the body of the Do function has to be a compound statement.
You also forgot a comma before {t, tickers}.
tickers = {"VNO", "AMB"};
fprop = {"Average50Day", "Average200Day"};
Do[
mydata = {t};
Do[
mydata = Append[mydata, FinancialData[t, i]],
{i, fprop}
];
Print[mydata];
SQLInsert[connt, "reit", {"ticker", "first", "second"}, mydata],
{t, tickers}
]
Cheers -- Sjoerd
On Oct 10, 12:44 pm, Michaell Taylor
<Michaell.Tay... at boxwoodmeans.com> wrote:
> I am new to Mathematica and am probably too stuck in other languages, but
> but having a hard time with a simple listing building looping structure.
> The code below is supposed to cycle through a list of stock tickers. =
For
> each ticker it builds a list of certain financial data elements and adds
> each element to a list. When the list is complete (all financial eleme=
nts
> obtained), the list is written to a Mysql database. The internal loopi=
ng
> structure seems to work fine. That is, if I execute the internal loop =
for a
> single ticker, the results are added to the database as planned.
>
> However, the outer structure causes a problem in that the list continues =
to
> grow with each ticker. The "mydata={}" line was meant to "reset" the=
list,
> but doesn't seem to be performing as expected.
>
> tickers = {"VNO", "AMB"}
>
> fprop = {"Average50Day", "Average200Day"}
>
> Do[
> mydata = {t}
> Do[
> mydata = Append[mydata, FinancialData[t, i]],
> {i, fprop}]
> Print[mydata]
> SQLInsert[connt, "reit" , {"ticker", "first", "second"}, mydata]
> {t, tickers}]
>
> My error, no doubt is obvious to some. Any guidance would be greatly
> appreciated.
>
> =========================
=
>
> Michaell Taylor, PhD
>
> Principal
> Boxwood Means, Inc.
> Two Stamford Landing, Suite 100
> 68 Southfield Ave.
> Stamford, CT 06902http://www.boxwoodmeans.com
> T: 203-653-4100
> F: 203-653-5090