我需要帮助将此代码类型从Do Loop While
和Do While Loop
转换为For...Next
循环。我使用Visual Basic 2010 Express作为运行这些代码的程序,如果有人可以帮助我,我将非常感谢。下面是需要转换为For ... 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
答案 0 :(得分:4)
试试这个:
For intNum As Integer = 0 To 50 Step 2
intSum += intNum ‘accumulator/running total
Next
注意:Step 2
相当于intNum += 2
循环中的Do
语法。