loops - trying to figure out how to call two variables in an array in powershell -


just starting learn loops , arrays. understand how call single variable in array ie:

$animals = gc "c:\temp\animals.txt" foreach ($animal in $animals) {write-host "the"$animal "sleeps tonight."} 

what i'm trying figure out how call 2 different variables 2 different arrays...ie:

$animals = gc "c:\temp\animals.txt" $colors = gc "c:\temp\colors.txt" 

this part i'm confused. how call foreach loop cycle though both files simultaneously?

desired output: white lion sleeps tonight, black panther sleeps tonight, etc...

one way use arry indexing. assuming both files have same line count:

$animals = gc c:\temp\animals.txt $colors = gc c:\temp\colors.txt  for($i=0; $i -lt $animals.length; $i++) {     #print first line animals       $animals[$i]      #print first line colors     $colors[$i] } 

Comments