while Döngüleri ve continue İfadeleri
Koşullar ve adım eylemleriyle döngü kurun.
while Döngüleri ve continue İfadeleri, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Repeat with while
A while loop repeats its body as long as a bool condition stays true. It checks the condition before each pass. 🔁
while (i < 5) {
std.debug.print("{}\n", .{i});
i += 1;
}Checked Before Each Pass
Zig tests the condition first, so a while whose condition starts false runs zero times. The body is never guaranteed to execute.
Avoiding Infinite Loops
Each iteration should move toward making the condition false. Forget to update the variable and the loop spins forever.
The continue Expression
Zig adds a continue expression after a colon. It runs at the end of every iteration, the perfect place for your step update.
var i: usize = 0;
while (i < 5) : (i += 1) {
work(i);
}Why the continue Slot Helps
Putting the step in the continue slot keeps it visible at the top and guarantees it runs even after a continue statement skips ahead.
Skip with continue
The continue statement jumps to the next iteration immediately, skipping the rest of the body but still running the continue expression.
while (i < 10) : (i += 1) {
if (i % 2 == 0) continue;
odd_sum += i;
}Stop Early with break
Use break to leave a while loop right away, even when the condition is still true. Control resumes after the loop.
while (true) {
if (done()) break;
}while as an Expression
A while can yield a value. break supplies the result on success, and an else clause provides the value when the loop finishes normally.
const found = while (i < n) : (i += 1) {
if (match(i)) break i;
} else null;Looping over Optionals
A while can keep unwrapping an optional, running while values are present and ending the moment it sees null.
while (it.next()) |item| {
process(item);
}Looping over Errors
Like if, a while can capture an error in an else branch when the unwrapped expression returns an error union instead of a value.
Infinite Loops on Purpose
Sometimes you want a deliberate forever loop. Writing while (true) with a break inside is the idiomatic event-loop pattern in Zig.
Quick Check
Where does Zig's continue expression run during a while loop?
Recap
You drove while: condition-first looping, the continue expression for clean steps, break and continue, and the value-returning expression form. 🎯
Sıkça Sorulan Sorular
“while Döngüleri ve continue İfadeleri” dersi ücretsiz mi?
Evet — “while Döngüleri ve continue İfadeleri” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.
“while Döngüleri ve continue İfadeleri” dersinde ne öğreneceğim?
Koşullar ve adım eylemleriyle döngü kurun. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Zig Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“while Döngüleri ve continue İfadeleri” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Bir Deyim ve İfade Olarak if
- while Döngüleri ve continue İfadeleri
- Aralıklar ve Öğeler Üzerinde for Döngüleri
- break, continue ve Etiketli Döngüler