Do 〜 Loop ( Until ):繰り返し処理を行う

Excel VBA リファレンス

スポンサードリンク

繰り返し処理を行う

書式
Do Until 条件式
    処理
Loop
Do
    処理
Loop Until 条件式
式の説明
条件式 ステートメントの終了条件を指定する式
この式の評価が false である間、ループが実行される
スポンサードリンク
関連カテゴリー
制御文 / 関数・ステートメント索引(D)
サンプルコード
Option Explicit

Sub main()
  Dim counter As Integer
  
  Debug.Print ("一つ目のループ")
  counter = 1
  Do Until counter > 2
    Debug.Print (counter)
    counter = counter + 1
  Loop
  
  Debug.Print ("二つ目のループ")
  counter = 1
  Do
    Debug.Print (counter)
    counter = counter + 1
  Loop Until counter > 2
  
  Debug.Print ("三つ目のループ")
  counter = 1
  Do Until counter > 0
    Debug.Print (counter)
    counter = counter + 1
  Loop
  
  Debug.Print ("四つ目のループ")
  counter = 1
  Do
    Debug.Print (counter)
    counter = counter + 1
  Loop Until counter > 0
  
  Debug.Print ("処理終了")
  
  '実行後、イミディエイト ウインドウに
  '以下の出力があります
  '
  '一つ目のループ
  '1
  '2
  '二つ目のループ
  '1
  '2
  '三つ目のループ
  '四つ目のループ
  '1
  '処理終了
End Sub
スポンサードリンク
関連カテゴリー
制御文 / 関数・ステートメント索引(D)