S_a_k_Uの日記みたいなDB

~サクゥーと呼ばないで~

ExcelのVBAマクロ

JavaしててVB書くと…
行末にセミコロン書いちゃったり、
条件式で等価を==と書いちゃったり、
コードの途中で Dim hoge As String とか書いちゃったり、
しちゃう訳ですけど、For文でbreakとかcontinueは?って引っ掛かってみたりw
Exitだったな、ContinueはVB.NETからか、とか。


こんな感じで、実現できるなと思ったものの、

Public Sub testLoop()

    Dim i As Integer

    Dim b As Boolean

    ' break のみ
    For i = 1 To 100
        ' break
        If (i > 50) Then
            Exit For
        End If
        Debug.Print "break loop : ", i
    Next i

    ' continue のみ
    For i = 1 To 100
        Do
            ' continue
            If (i > 50) Then
                Exit Do
            End If
            Debug.Print "NOT CONTINUE : ", i
        Loop While (False)
        Debug.Print "continue loop : ", i
    Next i
 
    ' break & continue のみ
    For i = 1 To 100
        b = False
        Do
            ' break
            If (i > 50) Then
                b = True
                Exit Do
            End If
            ' conitnue
            If (i < 10) Then
                Exit Do
            End If
            Debug.Print "NOT BREAK & CONTINUE : ", i
        Loop While (False)
        ' break
        If (b = True) Then
            Exit For
        End If
        Debug.Print "break & continue loop : ", i, b
    Next i
   
End Sub

continueはif文で書いたほうがええな。