VB.net 2013 - 嵌套循环三角形

时间:2014-09-24 11:49:51

标签: vb.net loops nested

我尝试使用VB.net设置嵌套for循环以生成以下输出:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10

你会如何解决这个问题?我已经有一段时间了,但我无法做到这一点......

2 个答案:

答案 0 :(得分:2)

  TextBox1.Multiline = True
  For k As Integer = 1 To 10
        For i As Integer = 1 To k
            TextBox1.AppendText(i.ToString & " ")
        Next
        TextBox1.AppendText(Environment.NewLine)
  Next

答案 1 :(得分:1)

 Dim i, j As Integer
 Label1.Text = ""
 For i = 1 To 10
     For j = 1 To i
         Label1.Text &= j & " "
     Next
     Label1.Text &= vbNewLine
 Next