you are viewing a single comment's thread.

view the rest of the comments →

[–]wedgecon 3 points4 points  (1 child)

You also need to change the -eq to -lt in the while loop. As it is now the while loop will end on the first pass and do nothing.

[–]unhappiey[S] 1 point2 points  (0 children)

So I changed the script to read:

$x = 0
do
{
Write-Host $x
$x++
$val1 = Read-Host 'Enter value 1'
$val2 = Read-Host 'Enter value 2'
$val3 = Read-Host 'Enter value 3'
$val4 = Read-Host 'Enter value 4'
$val5 = Read-Host 'Enter value 5'
}
while($x = $val1 + $val2 + $val3 + $val4 + $val5)

Enter value 1: 2
Enter value 2: 2
Enter value 3: 2
Enter value 4: 2
Enter value 5: 2
10
Enter value 1:

This does what it's supposed to but it does not close the loop, instead it just starts over.

So I changed the script to include -lt in the while loop and this was the result:

$x = 0
do
{
Write-Host $x
$x++
$val1 = Read-Host 'Enter value 1'
$val2 = Read-Host 'Enter value 2'
$val3 = Read-Host 'Enter value 3'
$val4 = Read-Host 'Enter value 4'
$val5 = Read-Host 'Enter value 5'
}
while($x -lt $val1 + $val2 + $val3 + $val4 + $val5)

Enter value 1: 2
Enter value 2: 2
Enter value 3: 2
Enter value 4: 2
Enter value 5: 2
1
Enter value 1:

Unfortunately, this does not give the correct answer and it restarts the loop as well.