Sub prog() Dim i As Integer Dim s As Long s = 0 i = 0 While i <= 10 s = s + i i = i + 2 Wend MsgBox "sの値は" & s & "です" End Sub |
i = 0 (ここから While 文に入る) ----- i = 0 は i<=10 を満たす s = s + 0 i = i + 2 (i=2) ----- i = 2 は i<=10 を満たす s = s + 2 i = i + 2 (i=4) ----- i = 4 は i<=10 を満たす s = s + 4 i = i + 2 (i=6) ----- … ----- i = 10 は i<=10 を満たす s = s + 10 i = i + 2 (i=12) ----- i = 12 は i<=10 を満たさない (While 文終了) |
1. Do While 条件式 命令文 (複数で良い) Loop |
2. Do Until 条件式 命令文 (複数で良い) Loop |
3. Do 命令文 (複数で良い) Loop While 条件式 |
4. Do 命令文 (複数で良い) Loop Until 条件式 |
|
Sub prog() Dim i As Integer Dim s As Long s = 0 i = 0 Do While i <= 10 s = s + i i = i + 2 Loop MsgBox "sの値は" & s & "です" End Sub |
Sub prog() Dim i As Integer Dim s As Long s = 0 i = 0 Do Until i > 10 s = s + i i = i + 2 Loop MsgBox "sの値は" & s & "です" End Sub |
Sub prog() Dim i As Integer Dim s As Long s = 0 i = 0 Do s = s + i i = i + 2 Loop While i <= 10 MsgBox "sの値は" & s & "です" End Sub |
Sub prog() Dim i As Integer Dim s As Long s = 0 i = 0 Do s = s + i i = i + 2 Loop Until i > 10 MsgBox "sの値は" & s & "です" End Sub |