title: How to print N number of primes in Visual Basic
body: <p>I have this visual basic code to receive user input and print out that many primes. For instance if a user inputs 5, the output should be: 1, 3, 5, 7, 11. Here is my code:</p>
  
  <pre><code>        Dim i, n, input, currentPrime As Integer
          Dim Wrap As String = Chr(10) &amp; Chr(13)
          ' input = TextBox2.Text
          currentPrime = 0
          txtOutput.Text = "Prime Numbers are : " &amp; Wrap
          'Do Until (currentPrime &lt;= input)
          For i = 0 To 500
              For j = 2 To Fix(i / 2) + 1
                  If i Mod j = 0 Then
                      n = 1
                  End If
              Next
              If n = 1 Then
                  n = 0
              Else
                  txtOutput.Text = txtOutput.Text &amp; Wrap &amp; i &amp; " is a prime number " &amp; Wrap
  
              End If
          Next
          currentPrime += 1
          'Loop
      End If
  </code></pre>
  
  <p>Do notice that the input and my Do loop is commented out. This is done because if I try to use this method nothing will print out and my program will lock up. However if I comment it out the program will print the prime numbers too 499.</p>
  
  <p>Does anyone know a way I can make this loop work? Any help is appreciated as I am a beginner in Visual Basic.</p>