2
我试图在Visual Basic中打印一个菱形。我的代码的上半部分工作完美,但由于某种原因,我无法让下半部分以类似的方式工作。在下半部分,在o(用于制作钻石)之后打印出空格,而o的数量减少会将程序发送到无限循环?谁能帮忙?Visual Basic循环永不结束
下半部分可能是完全错误的,我还在上
在这里工作是代码:
Option Explicit On
Imports System
Module diamond
Sub Main()
' The o variable will make the "o" part of the diamond, the space variable will be for places without an "o".
Dim row, spaces, o as Integer
'Dim index as integer
'For top half
' Count the row number.
row = 1
spaces = 9
o = 1
Do until row = 20
' Count of row increases every loop until half of diamond is done.
row +=1
' Write 1 less space every line.
For row = 1 to spaces
console.write(" ")
Next row
spaces -=1
'Write 2 more "o"'s every loop.
For row = 1 to o
Console.write("o")
Next row
o +=2
Console.Writeline
Loop
'Top of the diamond is done
'This is the bottom half, which will not work.
row = 20
Do until row = 40
row +=1
For row = 20 to spaces
Console.write(" ")
Next row
spaces +=1
'Write 2 less "o"'s every loop.
For row = 20 to o
Console.write("o")
Next row
o -=2
Console.Writeline
Loop
End Sub
End Module
请在发布时仔细考虑缩进代码 - 这种方式很难阅读。 – Oded