Junior — Middle
Vai jūs varat nosaukt ciklu veidus, kas tiek izmantoti programmēšanā, izņemot For ciklu?
sobes.tech AI
Atbilde no AI
Papildus for ciklam, programmēšanā plaši tiek izmantoti šādi ciklu veidi:
-
while — izpilda cikla ķermeni, kamēr nosacījums ir patiesība.
int i = 0; while (i < 5) { System.out.println(i); i++; } -
do-while — vispirms izpilda cikla ķermeni, tad pārbauda nosacījumu; garantē vismaz vienu izpildi.
int i = 0; do { System.out.println(i); i++; } while (i < 5); -
foreach (uzlabots for) — tiek izmantots kolekciju vai masīvu elementu pārlūkošanai.
int[] numbers = {1, 2, 3}; for (int num : numbers) { System.out.println(num); }
Šie cikli ļauj elastīgi organizēt atkārtojošās darbības kodā.