永发信息网

VB 把for改成do循环语句

答案:3  悬赏:0  手机版
解决时间 2021-07-29 08:56
  • 提问者网友:做自己de王妃
  • 2021-07-28 23:00

将下面的程序改成do while ...loop怎么改?

Private Sub Form_Click()
Dim i As Integer, j As Integer

For i = 1 To 5
Print Tab(30 - i * 2);
For j = 1 To i * 2 - 1
Print "* ";
Next j
Next i
For i = 4 To 1 Step -1
Print Tab(30 - i * 2);
For j = 1 To i * 2 - 1
Print "* ";
Next j
Next i
End Sub

最佳答案
  • 五星知识达人网友:持酒劝斜阳
  • 2021-07-28 23:38
Private Sub Form_Click() Dim i As Integer, j As Integer i = 1 j = 1 Do While (i <= 5) Print Tab(30 - i * 2); Do While (j <= i * 2 - 1) Print "* "; j = j + 1 Loop i = i + 1 j = 1 Loop i = 4 j = 1 Do While (i >= 1) Print Tab(30 - i * 2); Do While (j <= i * 2 - 1) Print "* "; j = j + 1 Loop i = i - 1 j = 1 Loop End Sub
全部回答
  • 1楼网友:第幾種人
  • 2021-07-29 00:17

Private Sub Form_Click() Dim i As Integer, j As Integer

i = 1: j = 1

Do While i <= 5 Print Tab(30 - i * 2); For j = 1 To i * 2 - 1 Print "* "; Next j i = i + 1 Loop

i = 4 Do While i >= 1 Print Tab(30 - i * 2); For j = 1 To i * 2 - 1 Print "* "; Next j i = i - 1 Loop End Sub

该程序用到了双层循环,而do while ...loop 不适合该多层循环处理

  • 2楼网友:蕴藏春秋
  • 2021-07-28 23:56

Private Sub Form_Click() Dim i As Integer, j As Integer

i = 1 j = 1 Do While (i <= 5) Print Tab(30 - i * 2); Do While (j <= i * 2 - 1) Print "* "; j = j + 1 Loop i = i + 1 j = 1 Loop i = 4 j = 1 Do While (i >= 1) Print Tab(30 - i * 2); Do While (j <= i * 2 - 1) Print "* "; j = j + 1 Loop i = i - 1 j = 1 Loop

End Sub

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯