Files
roma-dxunvrs 4fabe16272 04.09
2026-09-04 22:55:43 +03:00

46 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Позволяют избегать дублирование кода, помогают обходить [[Массивы|массивы]]
## С предусловием - while
```Java
int x = 100;
while (x > 0) {
x -= 1;
}
```
## С постусловием - do-while
Всегда выполнится хотя бы один раз
```Java
do {
x -= 1;
} while (x > 0);
```
## Цикл for
Цикл с счетчиком
```Java
for (int i = 0; i < arr.length; i++) {
}
```
Или для прохода по массивам/коллекциям
```Java
for (int num: nums) {
}
```
Для массивов - создает обычный цикл с счетчиком, для коллекций - берет их итератор
## continue и break
break - выходит из текущего цикла, итерация не продолжается
continue - переходит к следующей итерации без завершения текущей
Могут использоваться с метками
```Java
outer:
for (int[] inner: array) {
for (int element: inner) {
if (...) continue;
if (...) continue outer;
if (...) break;
if (...) break outer;
}
}
```
Далее: [[Функции]]