VB FOR。下一个。 LOOP - 数字的平方根

时间:2016-11-03 04:14:29

标签: visual-studio

如何在程序中正确使用For Next循环。是否必须有For Next循环的计数器。例如num = 1 to 1000或者我可以让用户输入计数器的任何数字。

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

1 个答案:

答案 0 :(得分:0)

这里是如何制作Sqrt功能并成功使用它,不需要使用for循环来做你想做的事情

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