Циклічні структури (Visual Basic)

  1. Цикли while While Loops
  2. Do-цикли Do Loops
  3. Цикли for For Loops
  4. Цикли foreach For Each Loops

Циклічні структури Visual Basic дозволяють виконувати одну або кілька рядків коду кілька разів. Visual Basic loop structures allow you to run one or more lines of code repetitively. Оператори в циклічної структури можна повторити, поки умова True, поки умова False, вказане число раз або один раз для кожного елемента в колекції. You can repeat the statements in a loop structure until a condition is True, until a condition is False, a specified number of times, or once for each element in a collection.

Нижче показана структура циклу, виконує набір інструкцій, поки умова не прийме значення true: The following illustration shows a loop structure that runs a set of statements until a condition becomes true:

Цикли while While Loops

While ... End While виконує набір інструкцій до тих пір, поки умова, заданий в While інструкція є True. The While ... End While construction runs a set of statements as long as the condition specified in the While statement is True. Додаткові відомості див. У розділі хоча ... Завершити оператор While . For more information, see While ... End While Statement .

Do-цикли Do Loops

Do ... Loop дозволяє перевірити умова на початку або наприкінці циклічної структури. The Do ... Loop construction allows you to test a condition at either the beginning or the end of a loop structure. Можна також вказати, чи слід повторювати цикл, поки значення умови одно True або поки воно не стане True. You can also specify whether to repeat the loop while the condition remains True or until it becomes True. Додаткові відомості див. У розділі зробити ... Цикл інструкції . For more information, see Do ... Loop Statement .

Цикли for For Loops

For ... Next виконує задану кількість разів. The For ... Next construction performs the loop a set number of times. Вона використовує змінну управління циклом, також званий лічильника, щоб відстежувати повторень. It uses a loop control variable, also called a counter, to keep track of the repetitions. Можна вказати початкове і кінцеве значення для цього лічильника і при необхідності можна вказати величину, на який він збільшує за одне повторення до наступного. You specify the starting and ending values ​​for this counter, and you can optionally specify the amount by which it increases from one repetition to the next. Додаткові відомості див. У розділі для ... Наступний оператор . For more information, see For ... Next Statement .

Цикли foreach For Each Loops

For Each ... Next виконує набір інструкцій один раз для кожного елемента в колекції. The For Each ... Next construction runs a set of statements once for each element in a collection. Вкажіть керуючої змінної циклу, але немає необхідності визначення її початкового або кінцевого значення. You specify the loop control variable, but you do not have to determine starting or ending values ​​for it. Додаткові відомості див. У розділі для кожного ... Наступний оператор . For more information, see For Each ... Next Statement .

Див. Також See also