0

我需要帮助将这种代码类型从循环转换为Do Loop While循环。我正在使用 Visual Basic 2010 Express 作为运行这些代码的程序,如果有人能帮助我,我将不胜感激。下面是需要转换为 For...Next 循环类型的代码。再次感谢任何可以提供帮助的人。Do While LoopFor...Next

Private Sub btnDo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDo.Click  
   Dim intNum, intSum As IntegerDo  
   intSum += intNum    ‘accumulator/running total  
   intNum += 2        ‘update intNum   
   Loop While (intNum <= 50)  
       Me.lblDoAnswer.Text = intSum.ToString  
End Sub

Private Sub btnDoWhile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)      Handles btnDoWhile.Click Dim intNum, intSum As Integer    
   Do While (intNum <= 50)  
       intSum += intNum    ‘accumulator/running total  
       intNum += 2        ‘update intNum  
   Loop  
   Me.lblDoWhileAnswer.Text = intSum.ToString  
End Sub
4

1 回答 1

4

尝试这个:

For intNum As Integer = 0 To 50 Step 2
    intSum += intNum    ‘accumulator/running total
Next

注意:与循环中的语法Step 2等效。intNum += 2Do

于 2013-11-01T12:29:34.920 回答