$scores = [ordered]@{
Jack = 81;
Mike = 78;
Mark = 99;
Jim = 64;
}
$grades = [ordered]@{}
$len = $scores.Count
for ($n=0;$n -lt $len; $n++){
if ($($scores.values)[$n] -gt 65){
$grades += @{$($scores.keys)[$n] = $($scores.keys)[$n]}
$grades[$n] = $($scores.values)[$n] = "PASS"
}
else{
$grades += @{$($scores.keys)[$n] = $($scores.keys)[$n]}
$grades[$n] = $($scores.values)[$n] = "FAIL"
}
}
$grades
=======THE ABOVE WORKS IN POWERSHELL JUST FINE
*******BELOW IS THE PROBLEM IN POWERSHELL (This structure works in Python)
$scores = [ordered]@{
Jack = 81;
Mike = 78;
Mark = 99;
Jim = 64;
}
$grades = [ordered]@{}
foreach($key in $scores){
if ($scores[$key] -gt 65){
$grades[$key] = "PASS"
}
else{
$grades[$key] = "FAIL"
}
}
$grades
======== Here is the correct FOR loop output:
******** Here is the output from FOREACH:
Please show me how the FOREACH loop is failing.
(Any improvement on the FOR loop is frosting on the cake!)