Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Nested for loop

Closed Thread
 
Thread Tools Display Modes
Old 03-02-2008   #1 (permalink)
pjofx
Guest


 

Nested for loop

Hi!

I am trying to run a nested for loop:

$qqq = Import-Csv d:\work\abc.csv
$uuu = Import-Csv d:\work\bbb.csv
$qqq
$uuu

for ( $j = 0; $j -lt $qqq.length; $j++)
{

for($counter = 0; $counter -lt $uuu.length; $counter++)
{
( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname -eq
$qqq[$j].Pair } )
}

$counter loop works fine but $j loop does not work.
The $qqq.length is correct.

Please point out what mistake(s) I made.

pjo
Old 03-02-2008   #2 (permalink)
Shay Levi
Guest


 

Re: Nested for loop


Just Guessing:

$qqq[$j+1].Pair


Can you post the csv's or a sample ones? What exactly is not working with
the $j loop ?


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi!
>
> I am trying to run a nested for loop:
>
> $qqq = Import-Csv d:\work\abc.csv
> $uuu = Import-Csv d:\work\bbb.csv
> $qqq
> $uuu
> for ( $j = 0; $j -lt $qqq.length; $j++)
> {
> for($counter = 0; $counter -lt $uuu.length; $counter++)
> {
> ( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname -eq
> $qqq[$j].Pair } )
> }
> $counter loop works fine but $j loop does not work. The $qqq.length is
> correct.
>
> Please point out what mistake(s) I made.
>
> pjo
>

Old 03-02-2008   #3 (permalink)
RichS
Guest


 

RE: Nested for loop

What you are doing with the outside loop seems correct in that this works
fine for me

$qqq = import-csv songlist.csv
for ($j=1; $j -lt $qqq.length; $j++){$qqq[$j].Song}

The code that you posted is missing a closing } at the end. Not sure if
that is your error or just missed on the post
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"pjofx" wrote:
Quote:

> Hi!
>
> I am trying to run a nested for loop:
>
> $qqq = Import-Csv d:\work\abc.csv
> $uuu = Import-Csv d:\work\bbb.csv
> $qqq
> $uuu
>
> for ( $j = 0; $j -lt $qqq.length; $j++)
> {
>
> for($counter = 0; $counter -lt $uuu.length; $counter++)
> {
> ( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname -eq
> $qqq[$j].Pair } )
> }
>
> $counter loop works fine but $j loop does not work.
> The $qqq.length is correct.
>
> Please point out what mistake(s) I made.
>
> pjo
>
Old 03-02-2008   #4 (permalink)
pjofx
Guest


 

Re: Nested for loop

On 3$B7n(B2$BF|(B, $B8a8e(B9:32, Shay Levi <n...@xxxxxx> wrote:
Quote:

> Just Guessing:
>
> $qqq[$j+1].Pair
>
> Can you post the csv's or a sample ones? What exactly is not working with
> the $j loop ?
>
> -----
> Shay Levi
> $cript Fanatichttp://scriptolog.blogspot.com
>
Quote:

> > Hi!
>
Quote:

> > I am trying to run a nested for loop:
>
Quote:

> > $qqq = Import-Csv d:\work\abc.csv
> > $uuu = Import-Csv d:\work\bbb.csv
> > $qqq
> > $uuu
> > for ( $j = 0; $j -lt $qqq.length; $j++)
> > {
> > for($counter = 0; $counter -lt $uuu.length; $counter++)
> > {
> > ( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname -eq
> > $qqq[$j].Pair } )
> > }
> > $counter loop works fine but $j loop does not work. The $qqq.length is
> > correct.
>
Quote:

> > Please point out what mistake(s) I made.
>
Quote:

> > pjo
Yes

abc.csv is:
Pair
EURUSD
GBPUSD
USDJPY
USDCHF
USDCAD
AUDUSD
NZDUSD
GBPJPY
GBPCHF
EURJPY
EURGBP
EURCHF
EURAUD
EURCAD
AUDCAD
CHFJPY
AUDJPY
NZDJPY
AUDNZD

bbb.csv is:
column name
EURUSD
1. kqjdkajdhlkkd
2. tgenjil;l;
3.htyhdjiigf

<U>GBPUSD</U>:
1.oriiuj
2.qegsrh
3.kjyf
4.ygbtfseb

and so on

maybe the <U> is causing the problem.

Thanks.
Old 03-02-2008   #5 (permalink)
pjofx
Guest


 

Re: Nested for loop

On 3$B7n(B2$BF|(B, $B8a8e(B9:43, RichS <Ri...@xxxxxx> wrote:
Quote:

> What you are doing with the outside loop seems correct in that this works
> fine for me
>
> $qqq = import-csv songlist.csv
> for ($j=1; $j -lt $qqq.length; $j++){$qqq[$j].Song}
>
> The code that you posted is missing a closing } at the end. Not sure if
> that is your error or just missed on the post
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
> "pjofx" wrote:
Quote:

> > Hi!
>
Quote:

> > I am trying to run a nested for loop:
>
Quote:

> > $qqq = Import-Csv d:\work\abc.csv
> > $uuu = Import-Csv d:\work\bbb.csv
> > $qqq
> > $uuu
>
Quote:

> > for ( $j = 0; $j -lt $qqq.length; $j++)
> > {
>
Quote:

> > for($counter = 0; $counter -lt $uuu.length; $counter++)
> > {
> > ( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname -eq
> > $qqq[$j].Pair } )
> > }
>
Quote:

> > $counter loop works fine but $j loop does not work.
> > The $qqq.length is correct.
>
Quote:

> > Please point out what mistake(s) I made.
>
Quote:

> > pjo
Thanks.

The missing } is a posting error.
the real code has it.
Old 03-02-2008   #6 (permalink)
pjofx
Guest


 

Re: Nested for loop

I found it !

simple error !

the elements in the first csv must have the following format.
<U>GBPUSD</U>:
except fpr the first one or

delete <U> and </U>:

How do I do this ?

bbb.csv is:
column name
EURUSD
1. kqjdkajdhlkkd
2. tgenjil;l;
3.htyhdjiigf

<U>GBPUSD</U>:
1.oriiuj
2.qegsrh
3.kjyf
4.ygbtfseb

and so on




On 3$B7n(B2$BF|(B, $B8a8e(B9:59, pjofx <asao.ishiz...@xxxxxx> wrote:
Quote:

> On 3$B7n(B2$BF|(B, $B8a8e(B9:32, Shay Levi <n...@xxxxxx> wrote:
>
>
>
Quote:

> > Just Guessing:
>
Quote:

> > $qqq[$j+1].Pair
>
Quote:

> > Can you post the csv's or a sample ones? What exactly is not working with
> > the $j loop ?
>
Quote:

> > -----
> > Shay Levi
> > $cript Fanatichttp://scriptolog.blogspot.com
>
Quote:
Quote:

> > > Hi!
>
Quote:
Quote:

> > > I am trying to run a nested for loop:
>
Quote:
Quote:

> > > $qqq = Import-Csv d:\work\abc.csv
> > > $uuu = Import-Csv d:\work\bbb.csv
> > > $qqq
> > > $uuu
> > > for ( $j = 0; $j -lt $qqq.length; $j++)
> > > {
> > > for($counter = 0; $counter -lt $uuu.length; $counter++)
> > > {
> > > ( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname -eq
> > > $qqq[$j].Pair } )
> > > }
> > > $counter loop works fine but $j loop does not work. The $qqq.length is
> > > correct.
>
Quote:
Quote:

> > > Please point out what mistake(s) I made.
>
Quote:
Quote:

> > > pjo
>
> Yes
>
> abc.csv is:
> Pair
> EURUSD
> GBPUSD
> USDJPY
> USDCHF
> USDCAD
> AUDUSD
> NZDUSD
> GBPJPY
> GBPCHF
> EURJPY
> EURGBP
> EURCHF
> EURAUD
> EURCAD
> AUDCAD
> CHFJPY
> AUDJPY
> NZDJPY
> AUDNZD
>
> bbb.csv is:
> column name
> EURUSD
> 1. kqjdkajdhlkkd
> 2. tgenjil;l;
> 3.htyhdjiigf
>
> <U>GBPUSD</U>:
> 1.oriiuj
> 2.qegsrh
> 3.kjyf
> 4.ygbtfseb
>
> and so on
>
> maybe the <U> is causing the problem.
>
> Thanks.
Old 03-02-2008   #7 (permalink)
Shay Levi
Guest


 

Re: Nested for loop


You can try regular expressions to extract/replace unwanted characters.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I found it !
>
> simple error !
>
> the elements in the first csv must have the following format.
> <U>GBPUSD</U>:
> except fpr the first one or
> delete <U> and </U>:
>
> How do I do this ?
>
> bbb.csv is:
> column name
> EURUSD
> 1. kqjdkajdhlkkd
> 2. tgenjil;l;
> 3.htyhdjiigf
> <U>GBPUSD</U>:
> 1.oriiuj
> 2.qegsrh
> 3.kjyf
> 4.ygbtfseb
> and so on
>
> On 3?2?, ??9:59, pjofx <asao.ishiz...@xxxxxx> wrote:
>
Quote:

>> On 3?2?, ??9:32, Shay Levi <n...@xxxxxx> wrote:
>>
Quote:

>>> Just Guessing:
>>>
>>> $qqq[$j+1].Pair
>>>
>>> Can you post the csv's or a sample ones? What exactly is not working
>>> with the $j loop ?
>>>
>>> -----
>>> Shay Levi
>>> $cript Fanatichttp://scriptolog.blogspot.com
>>>> Hi!
>>>>
>>>> I am trying to run a nested for loop:
>>>>
>>>> $qqq = Import-Csv d:\work\abc.csv
>>>> $uuu = Import-Csv d:\work\bbb.csv
>>>> $qqq
>>>> $uuu
>>>> for ( $j = 0; $j -lt $qqq.length; $j++)
>>>> {
>>>> for($counter = 0; $counter -lt $uuu.length; $counter++)
>>>> {
>>>> ( $zzz = $uuu[$counter+1].eaname | where { $uuu[$counter].eaname
>>>> -eq
>>>> $qqq[$j].Pair } )
>>>> }
>>>> $counter loop works fine but $j loop does not