Spec-Zone.ru › Octave 6

10.7 Оператор continue

Оператор continue, как и break, используется только внутри while, do-until или for циклов. Он пропускает остальную часть тела цикла, вызывая немедленное начало следующего цикла. Противопоставьте это оператору break, который полностью выходит из цикла. Вот пример:

# print elements of a vector of random
# integers that are even.

# first, create a row vector of 10 random
# integers with values between 0 and 100:

vec = round (rand (1, 10) * 100);

# print what we're interested in:

for x = vec
  if (rem (x, 2) != 0)
    continue;
  endif
  printf ("%d\n", x);
endfor

Если один из элементов vec — нечётное число, этот пример пропускает оператор вывода для этого элемента и возвращается к первой строке цикла.

Это не практичный пример использования оператора continue, но он должен дать вам чёткое понимание того, как он работает. Обычно цикл записывают так:

for x = vec
  if (rem (x, 2) == 0)
    printf ("%d\n", x);
  endif
endfor

© 1996–2022 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v6.4.0/The-continue-Statement.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API