Kotlin - Ders 5 (Döngü Yapıları) | 2021-06-10 tarihinde oluşturuldu.
// DÖNGÜ YAPILARI
// 1. while Döngüsü
var sayac:Int = 0
while (sayac < 10) {
println("while -> Sayacın değeri: " + sayac)
sayac++
}
println(sayac)

// 2. do-while döngüsü
do {
println("do-while -> Sayacın değeri: " + sayac)
sayac--
} while (sayac > 0)

// for döngüsü
for (i in 3..10) {
println("for -> i'nin değeri: " + i)
}

for (j in 6..15 step 2) {
println("for -> j'nin değeri: " + j)
}

for (m in 20 downTo 5 step 3) {
println("for -> m'nin değeri: " + m)
}

// NOT: eğer gerekiyorsa for içindeki döngü değişkeninin
// veri tipi belirlenebilir. Örnek: for (i:Int in 5..10) gibi...

sayac = 0
for (n in 1..100){
if(n % 5 != 0) {
continue
}
sayac++
//println(n + " 5 ile bölünmüyor!") kodu hata veriyor, n tamsayısı
// başta olduğunda tamsayı ile string toplanamayacağı için hata yükseltiyor.
// aşağıdaki kullanım tercih edilebilir.
println("" + n + ", 5 ile bölünüyor")
println("Sayacın değeri " + sayac)
if (n == 15) break
}

disDongu@for (x in 1..10) {
icDongu@for (y in 1..10) {
println("x: " + x + ", y: " + y)
if (x*y == 25) break@disDongu
}
}

// Normalde break ile çıkılan döngü, break'in direkt olarak içinde
// kullanıldığı döngüdür. Eğer dış kapsamdaki döngülerden çıkılmak
// isteniyorsa döngülere takma isim verilip break'te bu isim belirtilebilir.

ÇIKTILAR
System.out: while -> Sayacın değeri: 0
System.out: while -> Sayacın değeri: 1
System.out: while -> Sayacın değeri: 2
System.out: while -> Sayacın değeri: 3
System.out: while -> Sayacın değeri: 4
System.out: while -> Sayacın değeri: 5
System.out: while -> Sayacın değeri: 6
System.out: while -> Sayacın değeri: 7
System.out: while -> Sayacın değeri: 8
System.out: while -> Sayacın değeri: 9
System.out: 10
System.out: do-while -> Sayacın değeri: 10
System.out: do-while -> Sayacın değeri: 9
System.out: do-while -> Sayacın değeri: 8
System.out: do-while -> Sayacın değeri: 7
System.out: do-while -> Sayacın değeri: 6
System.out: do-while -> Sayacın değeri: 5
System.out: do-while -> Sayacın değeri: 4
System.out: do-while -> Sayacın değeri: 3
System.out: do-while -> Sayacın değeri: 2
System.out: do-while -> Sayacın değeri: 1
System.out: for -> i'nin değeri: 3
System.out: for -> i'nin değeri: 4
System.out: for -> i'nin değeri: 5
System.out: for -> i'nin değeri: 6
System.out: for -> i'nin değeri: 7
System.out: for -> i'nin değeri: 8
System.out: for -> i'nin değeri: 9
System.out: for -> i'nin değeri: 10
System.out: for -> j'nin değeri: 6
System.out: for -> j'nin değeri: 8
System.out: for -> j'nin değeri: 10
System.out: for -> j'nin değeri: 12
System.out: for -> j'nin değeri: 14
System.out: for -> m'nin değeri: 20
System.out: for -> m'nin değeri: 17
System.out: for -> m'nin değeri: 14
System.out: for -> m'nin değeri: 11
System.out: for -> m'nin değeri: 8
System.out: for -> m'nin değeri: 5
System.out: 5, 5 ile bölünüyor
System.out: Sayacın değeri 1
System.out: 10, 5 ile bölünüyor
System.out: Sayacın değeri 2
System.out: 15, 5 ile bölünüyor
System.out: Sayacın değeri 3
System.out: x: 1, y: 1
System.out: x: 1, y: 2
System.out: x: 1, y: 3
System.out: x: 1, y: 4
System.out: x: 1, y: 5
System.out: x: 1, y: 6
System.out: x: 1, y: 7
System.out: x: 1, y: 8
System.out: x: 1, y: 9
System.out: x: 1, y: 10
System.out: x: 1, y: 11
System.out: x: 1, y: 12
System.out: x: 1, y: 13
System.out: x: 1, y: 14
System.out: x: 1, y: 15
System.out: x: 1, y: 16
System.out: x: 1, y: 17
System.out: x: 1, y: 18
System.out: x: 1, y: 19
System.out: x: 1, y: 20
System.out: x: 2, y: 1
System.out: x: 2, y: 2
System.out: x: 2, y: 3
System.out: x: 2, y: 4
System.out: x: 2, y: 5
System.out: x: 2, y: 6
System.out: x: 2, y: 7
System.out: x: 2, y: 8
System.out: x: 2, y: 9
System.out: x: 2, y: 10
System.out: x: 2, y: 11
System.out: x: 2, y: 12
System.out: x: 2, y: 13
System.out: x: 2, y: 14
System.out: x: 2, y: 15
System.out: x: 2, y: 16
System.out: x: 2, y: 17
System.out: x: 2, y: 18
System.out: x: 2, y: 19
System.out: x: 2, y: 20
System.out: x: 3, y: 1
System.out: x: 3, y: 2
System.out: x: 3, y: 3
System.out: x: 3, y: 4
System.out: x: 3, y: 5
System.out: x: 3, y: 6
System.out: x: 3, y: 7
System.out: x: 3, y: 8
System.out: x: 3, y: 9
System.out: x: 3, y: 10
System.out: x: 3, y: 11
System.out: x: 3, y: 12
System.out: x: 3, y: 13
System.out: x: 3, y: 14
System.out: x: 3, y: 15
System.out: x: 3, y: 16
System.out: x: 3, y: 17
System.out: x: 3, y: 18
System.out: x: 3, y: 19
System.out: x: 3, y: 20
System.out: x: 4, y: 1
System.out: x: 4, y: 2
System.out: x: 4, y: 3
System.out: x: 4, y: 4
System.out: x: 4, y: 5
System.out: x: 4, y: 6
System.out: x: 4, y: 7
System.out: x: 4, y: 8
System.out: x: 4, y: 9
System.out: x: 4, y: 10
System.out: x: 4, y: 11
System.out: x: 4, y: 12
System.out: x: 4, y: 13
System.out: x: 4, y: 14
System.out: x: 4, y: 15
System.out: x: 4, y: 16
System.out: x: 4, y: 17
System.out: x: 4, y: 18
System.out: x: 4, y: 19
System.out: x: 4, y: 20
System.out: x: 5, y: 1
System.out: x: 5, y: 2
System.out: x: 5, y: 3
System.out: x: 5, y: 4
System.out: x: 5, y: 5

YORUMLAR | Bu konuya toplam (0) yorum yapılmış


YORUM YAZ
Adınızı Girin:  * Doldurulması zorunludur



   Doğrulama Kodu


KATEGORİLER
  Genel (4)
  Güvenlik (2)
  Program (6)
  Windows (7)
  Mobil (3)
  Python 3.X (16)
  PARDUS (5)
  M.E.B. (2)
  Donanım (1)
  Java (9)
  Robotik (11)
  JavaScript (1)
  Kotlin (8)
  Multimedia (1)
  deneme (0)

SON YAZILARIM
  2023 - 2024 7. Sınıf Seçmeli Robotik ve Kodlama Dersi Yıllık Planı | 2023-09-28
  Windows 10 Dosya ağ Paylaşım Hatası | 2022-04-19
  Kotlin - Ders 8 (Sınıflar) | 2022-03-28
  Kotlin - Ders 7 (Fonksiyonlar) | 2022-03-27
  e-Okul için GIMP ile Toplu Fotoğraf Boyutlandırma | 2022-01-13
  Pardus Üzerinde App Inventor Emulator Kurulumu ve Çalıştırılması | 2021-09-12
  Kotlin - Ders 6 (Koleksiyonlar) | 2021-06-11
  Kotlin - Ders 5 (Döngü Yapıları) | 2021-06-10
  Kotlin - Ders 4 (Karar Yapıları) | 2021-06-09
  ffmpeg ile Resim ve Ses Dosyalarını Videoya Dönüştürme | 2021-06-09