title: Read-Host in While loop with if statement
body: <p>This should be really simple, but I cannot make it work. I'm new to the PowerShell so my mistake is probably obvious. I'm trying to ask a user for an input using a while loop, and prompting the user to try again if what was entered was not numeric. In bash it would look like this:</p>
  
  <pre><code>while read -p "What is the first number? " first; do
  if [[ $first = *[[:digit:]]* ]]; then
  break   # if $first is numeric, break loop
  else
  echo "$first is not numeric. Enter a numeric value. "
  fi
  done
  </code></pre>
  
  <p>Here's what I have for the PS:</p>
  
  <pre><code>While ($first = (Read-Host "What is the first number?") -as [double]) {
  if ($first -eq $null) { Write-Host "Please enter a numeric value." }
  else { break }
  }
  </code></pre>
  
  <p>In the example above, I can break the loop fine when a number is entered, but I can't see the <code>Write-Host</code> statement if I type a string.</p>