-1

How can I correctly use the For Next loop in my program. Is it a must to have a counter for the For Next loop. For instance num = 1 to 1000 or can I have the user enter any number with the counter.

Module Module1

   Sub Main()
    Dim sq As Integer


    For num As Integer = num >= 



        Console.WriteLine("Please enter a number")
        num = Console.Read()

        sq = num * num



        Console.WriteLine("the square root is " & sq)

    Next

End Sub
End Module
Netherland
  • 11
  • 1
  • 7
  • whats the question? – Isaac Nov 03 '16 at 04:15
  • @Issac. How can i get the user to enter a number and find its sq in For next loop. – Netherland Nov 03 '16 at 04:22
  • 1
    so what's the real problem? If you want to read an integer why don't search for [Reading an integer from user input](http://stackoverflow.com/q/24443827/995714)? If you're **squaring** the number why asking for **square root** of the number? And why do you ask the user to enter 1000 times? – phuclv Nov 03 '16 at 04:28
  • you should learn vb 6.0 before you use it – Jack Siro Nov 03 '16 at 09:10

1 Answers1

0

here's how to make a Sqrt function and successfully using it no need to use a for loop to do what you want to do

Function Sqrt(x)As Integer
    Dim root As Integer
    root = x
    root = root ^ (1 / 2)    
    Sqrt = root    
End Function

Private Sub Command1_Click()
    Num = InputBox("Please enter a number")    
    Print "The square root of " & Num & " is " & Sqrt(Num)
End Sub
Jack Siro
  • 677
  • 10
  • 29