title: How to display output in the for loop horizontally?
body: <p>I'm creating a program that display n number of prime number (e.g. The program will display first 6 prime numbers if the user inputted 6). And I want the display 1 row contains 5 numbers. I did googled it around to find the solution but failed to find it.</p>
  
  <p>I have tried using if else statement to do it but not working</p>
  
  <pre><code>for ( $i = 3; $i -gt 0; ++$i ) #starting from 3
      {
          $sqrt = [math]::Sqrt($i)    #Optimize memory consumption
          for ( $j = 2; $j -le $sqrt; ++$j )    #Checked if it is divisible by any natural number
          {
              if ( $i % $j -eq 0 )    #if is prime number
              {
                  $prime = 1    #set to false
                  break    #stop taking into account
              }
          }
          if ( $prime -eq 0 )    #if not prime number
          {
              Write-Host ("$i")   #display prime number
  
              $count++    #set count to 1
              $turn++    #set turn to 1
          }
          $prime = 0    #is prime number
          if ( $count -eq $value )    #if until nth prime number
          {
              break    #stop taking into account
          }
          if ( $turn -eq 5 )
          {
             Write-Output(" ")
             $turn = 0
          }
      }
  </code></pre>
  
  <p>I'm expecting the result is like:<br>
  3
  5
  7
  11
  13</p>
  
  <p>17
  19
  23
  29
  31</p>
  
  <p>But it gave me the output like this:<br>
  3<br>
  5<br>
  7<br>
  11<br>
  13        </p>
  
  <p>17<br>
  19<br>
  23<br>
  29<br>
  31    </p>
  
  <p>Any suggestions / advice is welcomed. Thank you in advance.</p>