0Pricing
Scala for Backend Engineering & Functional Programming · Ders

Denetim Yapıları ve İşlevler

Scala'da koşullu ifadeleri (if/else), döngüleri ve basit işlev tanımlamayı öğrenin.

Denetim Yapıları ve İşlevler, CoddyKit'te ücretsiz bir Scala for Backend Engineering & Functional Programming dersidir. Bu, 3 dersinin 3. 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, Scala for Backend Engineering & Functional Programming öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Scala for Backend Engineering & Functional Programming kursu toplamda 3 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Guide Your Code's Path

Imagine your program as a journey. Sometimes you need to make decisions, like taking a left or right turn. Other times, you need to repeat an action, like walking several steps.

Control structures are tools that let your code make these decisions and repeat actions. They determine the order in which statements are executed, guiding the flow of your program.

Conditional Logic: If/Else

The most basic control structure is the if/else expression. It allows your program to execute different blocks of code based on whether a condition is true or false.

In Scala, if is an expression, meaning it always returns a value. This is a powerful feature compared to many other languages where if is just a statement.

If/Else in Action

Let's see how if/else works. This example checks if a number is greater than 5 and assigns a string based on the result.

object Main {
  def main(args: Array[String]): Unit = {
    val x = 10
    val result = if (x > 5) {
      "Greater"
    } else {
      "Smaller"
    }
    println(result)
  }
}

Handling Multiple Conditions

What if you have more than two possibilities? You can chain multiple conditions using else if to create more complex decision paths.

The code will check conditions in order. The first one that evaluates to true will have its code block executed, and the rest will be skipped.

Repeating Actions: While Loops

Sometimes you need to repeat a block of code until a certain condition is no longer met. This is where loops come in handy.

The while loop repeatedly executes a block of code as long as its condition remains true. Be careful not to create an infinite loop by always keeping the condition true!

While Loop Example

This simple while loop prints a message three times. Notice how the variable i is updated inside the loop to eventually make the condition i < 3 false.

object Main {
  def main(args: Array[String]): Unit = {
    var i = 0
    while (i < 3) {
      println(s"Count: $i")
      i = i + 1
    }
  }
}

Iterating with For Expressions

Scala's for expression is incredibly versatile for iteration. It can iterate over ranges, collections, and even filter values.

For now, let's focus on iterating over a simple range of numbers. The to keyword creates an inclusive range.

For Loop Code Example

Here's a for loop that iterates from 1 to 3 (inclusive) and prints each number. This is a common way to perform repetitive tasks for a known number of times.

object Main {
  def main(args: Array[String]): Unit = {
    for (i <- 1 to 3) {
      println(s"Number: $i")
    }
  }
}

Defining Your Own Functions

Functions are blocks of code designed to perform a particular task. They help you organize your code, make it reusable, and easier to understand.

In Scala, you define a function using the def keyword, followed by its name, parameters (with their types), and an optional return type. If the function returns Unit (nothing), the return type can be omitted.

Simple Function Example

Let's define a function called add that takes two integers and returns their sum. Notice how we call the function from our main method.

object Main {
  def add(a: Int, b: Int): Int = {
    a + b
  }
  def main(args: Array[String]): Unit = {
    val sum = add(5, 3)
    println(s"The sum is: $sum")
  }
}

Quick Check: Control Flow

What will the following Scala code print?

Recap: Control & Functions

Great job! In this lesson, you've learned to guide your code's execution:

  • if/else expressions for making decisions, returning a value based on conditions.
  • while loops for repeating actions as long as a condition is true.
  • for expressions for iterating over ranges and other sequences.
  • Defining functions to encapsulate reusable blocks of code.

These are fundamental building blocks for any program, allowing you to create dynamic and organized applications!

Sıkça Sorulan Sorular

“Denetim Yapıları ve İşlevler” dersi ücretsiz mi?

Evet — “Denetim Yapıları ve İşlevler” 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 Scala for Backend Engineering & Functional Programming kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Scala for Backend Engineering & Functional Programming kursu toplamda 3 dersten oluşur.

“Denetim Yapıları ve İşlevler” dersinde ne öğreneceğim?

Scala'da koşullu ifadeleri (if/else), döngüleri ve basit işlev tanımlamayı öğrenin. Scala for Backend Engineering & Functional Programming 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.

Scala for Backend Engineering & Functional Programming öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Scala for Backend Engineering & Functional Programming, 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, 3 dersinin 3. dersidir.

“Denetim Yapıları ve İşlevler” 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 Scala for Backend Engineering & Functional Programming dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Scala for Backend Engineering & Functional Programming 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

  1. Scala ile Çalışmaya Başlama
  2. Temel Söz Dizimi ve Türler
  3. Denetim Yapıları ve İşlevler
← Scala for Backend Engineering & Functional Programming Sayfasına Dön