这个代码不明白
功能是画一个正方形,边长等待用户输入,大于20就显示错误消息
Dim row As Integer
Dim colum As Integer
Dim result As Integer
Console.Write( "请输入个数: ")
result = Console.ReadLine
If result <= 20 Then
row = 1
Do While row <= result
colum = 1
Do While colum <= result
Console.Write( "* ")
colum = colum + 1
Loop
Console.WriteLine()
row = row + 1
Loop
Console.ReadLine()
Else
Console.WriteLine( "数字太大 ")
End If
=================================
上面的代码能正常显示一个正方形,但是下面为什么不可以,只是把row 和colum的初始化放到了上面:
Dim row As Integer = 1
Dim colum As Integer = 1
Dim result As Integer
Console.Write( "请输入个数: ")
result = Console.ReadLine
If result <= 20 Then
Do While row <= result
Do While colum <= result
Console.Write( "* ")
colum = colum + 1
Loop
Console.WriteLine()
row = row + 1
Loop
Console.ReadLine()
Else
Console.WriteLine( "数字太大 ")
End If
============================
上面的代码只是会显示一行的边,其余的不显示
为什么不能在一开始就声明变量的初始数值呢?
[解决办法]
在循环中有时变量row或者colum需要重新置1.你在声明时赋初值当然可以,但是把重新置1的语句删除就不行了.