Ana Sayfa Hakkımda Dersler Blog MikrofondaOn The Mic İletişim Projeler Yakında
DerslerLessons TEMEL · C#

C# Temelleri — For Döngüsü C# Basics — For Loop

8 dk okuma 8 min read · Emre Ulutabak
1
Döngü nedir? What is a loop?

Hayatta bazı işleri tekrar tekrar yaparsın. Merdiven çıkarken her basamağa aynı hareketle çıkarsın. Tek fark, bunu bir kez değil birçok kez yapmandır.

Yazılımda da aynı mantık vardır. Bir işlemi tekrar tekrar yapmak gerektiğinde her satırı elle yazmak yerine döngü kullanılır.

In life, you repeat some actions again and again. When climbing stairs, you make the same movement on every step. The only difference is that you do it many times.

Software works the same way. When an operation needs to be repeated, instead of writing the same code manually, you use a loop.

csharp
for (int i = 1; i <= 3; i++)
{
    Console.WriteLine("Merhaba!");
}
💡
Döngü, aynı işi kontrollü şekilde tekrar ettirir. A loop repeats the same action in a controlled way.
2
Neden kullanılır? Why is it used?

10 kez ekrana yazı yazdırmak istiyorsan bunu 10 satırla da yapabilirsin. Ama bu hem sıkıcıdır hem de kodu büyütür.

For döngüsü sayesinde tekrar eden işleri daha kısa, daha okunur ve daha yönetilebilir şekilde yazarsın.

If you want to print something 10 times, you could write 10 lines. But that is both repetitive and messy.

With a for loop, you can write repetitive tasks in a shorter, cleaner, and more manageable way.

3
For yapısı The structure of for

Bir for döngüsü genelde üç parçadan oluşur: başlangıç, koşul ve artış.

Yani önce sayaç oluşturulur, sonra döngünün devam edip etmeyeceği kontrol edilir, ardından her turda sayaç güncellenir.

A for loop usually has three parts: initialization, condition, and increment.

First, a counter is created. Then the condition is checked. After each round, the counter is updated.

csharp
for (int i = 0; i < 5; i++)
{
    Console.WriteLine(i);
}
💡
Burada i önce 0 olur, koşul kontrol edilir, kod çalışır, sonra i bir artırılır. Here, i starts at 0, the condition is checked, the code runs, and then i increases by one.
4
Sayaç mantığı Counter logic

Döngülerdeki sayaç değişkeni çoğu zaman i olur. Bu değişken tur sayısını takip eder.

Aslında i'nin özel bir gücü yoktur; sadece geleneksel bir isimdir. İstersen başka isim de verebilirsin ama kısa ve sade olması tercih edilir.

In loops, the counter variable is often called i. It tracks how many times the loop has run.

There is nothing magical about i; it is just a common convention. You can name it differently, but short and simple names are usually preferred.

csharp
for (int sayi = 1; sayi <= 5; sayi++)
{
    Console.WriteLine($"Tur: {sayi}");
}
💡
Sayaç değişkeni döngünün kalbidir. Nereye kadar ve kaç kez çalışacağını o belirler. The counter variable is the heart of the loop. It determines how far and how many times it runs.
5
Altın kurallar Golden rules

Döngüler güçlüdür ama dikkatsiz kullanılırsa hata üretir. Özellikle sonsuz döngü ve yanlış sayaç mantığı çok yaygın problemler oluşturur.

Loops are powerful, but if used carelessly they can cause errors. Infinite loops and incorrect counter logic are especially common problems.

💡
Koşulu dikkatli yaz. Yanlış koşul döngünün hiç çalışmamasına ya da fazla çalışmasına neden olabilir. Write the condition carefully. A wrong condition can cause the loop to never run or run too many times.
💡
Sayaç değişimini unutma. Aksi halde döngü takılı kalabilir. Do not forget to update the counter. Otherwise, the loop may get stuck.
💡
Döngü içinde gerçekten tekrar etmesi gereken işi yaz. Gereksiz kod kalabalığı oluşturma. Only put the code that truly needs to repeat inside the loop. Avoid unnecessary clutter.
MİNİ QUIZ MINI QUIZ
Aşağıdakilerden hangisi doğrudur? Which of the following is correct?
for döngüsü sadece bir kez çalışır A for loop only runs once
for döngüsü tekrar eden işleri yönetmek için kullanılır A for loop is used to manage repetitive tasks
for içinde koşul yazılmaz No condition is written inside a for loop
Sayaç değişkeni zorunlu olarak x olmalıdır The counter variable must be named x