diff --git a/tr/02.3.md b/tr/02.3.md index 54815068..4b18cf2e 100644 --- a/tr/02.3.md +++ b/tr/02.3.md @@ -8,9 +8,9 @@ Akış kontrolü programcılıkta en büyük icattır. Onun sayesinde, basit kon ### if -'if' kelimesi büyük ihtimalle programlarında en sık geçen kelimedir. Eğer şartlar sağlanırsa birşeyler yapar, sağlanmazsa başka şeyler yapar. +`if` kelimesi büyük ihtimalle programlarında en sık geçen kelimedir. Eğer şartlar sağlanırsa birşeyler yapar, sağlanmazsa başka şeyler yapar. -'if' şartları için Go da paranteze gerek yoktur. +`if` şartları için Go da paranteze gerek yoktur. if x > 10 { fmt.Println("x is greater than 10") @@ -18,7 +18,7 @@ Akış kontrolü programcılıkta en büyük icattır. Onun sayesinde, basit kon fmt.Println("x is less than or equal to 10") } -Go da çok işe yarar bir 'if' kullanımı, şart ifadesinden önce değişken tanımlama yapmaktır. Bu değişkenin kapsamı sadece 'if' blok alanı içerisinde geçerlidir. +Go da çok işe yarar bir `if` kullanımı, şart ifadesinden önce değişken tanımlama yapmaktır. Bu değişkenin kapsamı sadece `if` blok alanı içerisinde geçerlidir. // x'i tanımla, ve 10 dan büyük olup olmadığını kontrol et if x := computedValue(); x > 10 { @@ -30,7 +30,7 @@ Go da çok işe yarar bir 'if' kullanımı, şart ifadesinden önce değişken t // Bu satır derlenemez fmt.Println(x) -Birden fazla şart için if-else kullanın. +Birden fazla şart için `if-else` kullanın. if integer == 3 { fmt.Println("The integer is equal to 3") @@ -42,7 +42,7 @@ Birden fazla şart için if-else kullanın. ### goto -Go has a `goto` keyword, but be careful when you use it. `goto` reroutes the control flow to a previously defined `label` within the body of same code block. +Go da `goto` terimi mevcuttur fakat kullanırken dikkatli olun. `goto` programın kontrol akışını önceden belirlenmiş aynı gövde içindeki bir `label` a yönlendirir. func myFunc() { i := 0 @@ -52,19 +52,19 @@ Go has a `goto` keyword, but be careful when you use it. `goto` reroutes the con goto Here // jump to label "Here" } -The label name is case sensitive. +Label'ın adı büyük-küçük harfe duyarlıdır. ### for -`for` is the most powerful control logic in Go. It can read data in loops and iterative operations, just like `while`. +`for` Go da bulunan en güçlü kontrol lojiğidir. Datayı döngüsel olarak ve tekrarlı işlemlerle okuyabilir, `while` döngüsü gibi. for expression1; expression2; expression3 { //... } - -`expression1`, `expression2` and `expression3` are all expressions, where `expression1` and `expression3` are variable definitions or return values from functions, and `expression2` is a conditional statement. `expression1` will be executed once before looping, and `expression3` will be executed after each loop. -Examples are more useful than words. +`expression1`, `expression2` ve `expression3` birer ifade olmak üzere, `expression1` ve `expression3` değişken tanımlama veya bir fonksiyondan dönen return olabilirken, `expression2` ise kontrol ifadesidir. `expression1` ifadesi döngüye girmeden önce bir kere işlenecektir. `expression3` ise her döngü sonunda işlenir. + +Örnekler düz yazıdan daha yararlı olacaktır. package main import "fmt" @@ -78,23 +78,23 @@ Examples are more useful than words. } // Print:sum is equal to 45 -Sometimes we need multiple assignments, but Go doesn't have the `,` operator, so we use parallel assignment like `i, j = i + 1, j - 1`. +Bazen birden fazla atama yapmak gerekir fakat Go bunun için kullanılacak bir `,` operatörü yoktur. Biz de `i, j = i + 1, j - 1` gibi paralel atamalar yaparız. -We can omit `expression1` and `expression3` if they are not necessary. +İhtiyacımız yoksa `expression1` ve `expression1` ifadelerini çıkarabiliriz. sum := 1 for ; sum < 1000; { sum += sum } - -Omit `;` as well. Feel familiar? Yes, it's identical to `while`. + +Hatta `;` bile çıkarılabilir. Tanıdık geldi mi? Evet, tamamen `while` gibi oldu. sum := 1 for sum < 1000 { sum += sum } - -There are two important operations in loops which are `break` and `continue`. `break` jumps out of the loop, and `continue` skips the current loop and starts the next one. If you have nested loops, use `break` along with labels. + +Döngülerde `break` ve `continue` adında iki önemli işlem vardır. `break` döngüden çıkartır ve `continue` o anki tekrarı atlar ve sonraki tekrara geçer. Eğer birden fazla iç içe döngüleriniz varsa `break` ile labelları kullabilirsiniz. for index := 10; index>0; index-- { if index == 5{ @@ -104,15 +104,15 @@ There are two important operations in loops which are `break` and `continue`. `b } // break prints 10、9、8、7、6 // continue prints 10、9、8、7、6、4、3、2、1 - -`for` can read data from `slice` and `map` when it is used together with `range`. + +`for` döngüsü `range` kullanıldığında `slice` ve `map` de bulunan datayı okuyabilir. for k,v:=range map { fmt.Println("map's key:",k) fmt.Println("map's val:",v) } - -Because Go supports multi-value returns and gives compile errors when you don't use values that were defined, you may want to use `_` to discard certain return values. + +Go da birden fazla değer return yapılabildiği ve kullanılmayan bir değişken olduğunda derleyici hata verdiği için, kullanmak istemediğiniz değişkenler için `_` kullanabilirsiniz. for _, v := range map{ fmt.Println("map's val:", v) @@ -120,7 +120,7 @@ Because Go supports multi-value returns and gives compile errors when you don't ### switch -Sometimes you may find that you are using too many `if-else` statements to implement some logic, which may make it difficult to read and maintain in the future. This is the perfect time to use the `switch` statement to solve this problem. +Bazı durumlarda çok fazla `if-else` kullandığınızı farkedebilirsiniz. Bu programı okumayı zorlaştırır ve gelecekte bakım yapmayı zorlaştırabilir. Bu durumda problemi çözmek için `switch` kullanmak mükemmeldir. switch sExpr { case expr1: @@ -132,8 +132,8 @@ Sometimes you may find that you are using too many `if-else` statements to imple default: other code } - -The type of `sExpr`, `expr1`, `expr2`, and `expr3` must be the same. `switch` is very flexible. Conditions don't have to be constants and it executes from top to bottom until it matches conditions. If there is no statement after the keyword `switch`, then it matches `true`. + +`sExpr`, `expr1`, `expr2`, ve `expr3` ifadelerinin türleri aynı olmalıdır. `switch` çok esnektir. Şartlar sabit olmak zorunda değildir ve şart sağlanana kadar yukarıdan aşağıya doğru çalışır. Eğer `switch` in ardından bir ifade gelmiyorsa `true` olarak görülür. i := 10 switch i { @@ -146,8 +146,8 @@ The type of `sExpr`, `expr1`, `expr2`, and `expr3` must be the same. `switch` is default: fmt.Println("All I know is that i is an integer") } - -In the fifth line, we put many values in one `case`, and we don't need to add the `break` keyword at the end of `case`'s body. It will jump out of the switch body once it matched any case. If you want to continue to matching more cases, you need to use the`fallthrough` statement. + +Beşinci satırdaki gibi `case` içinde birden fazla değer olabilir. `case` sonlarına `break` eklemeye gerek yoktur, şart sağlanıp işlem yapıldıktan sonra çıkacaktır. Eğer çıkmasını istemiyorsanız `fallthrough` ifadesini kullanarak bir sonraki şarta devam edebilirsiniz. integer := 6 switch integer { @@ -179,25 +179,24 @@ This program prints the following information. ## Functions -Use the `func` keyword to define a function. +`func` terimini kullanarak bir fonksiyon tanımlayın. func funcName(input1 type1, input2 type2) (output1 type1, output2 type2) { // function body // multi-value return return value1, value2 } - -We can extrapolate the following information from the example above. -- Use keyword `func` to define a function `funcName`. -- Functions have zero, one or more than one arguments. The argument type comes after the argument name and arguments are separated by `,`. -- Functions can return multiple values. -- There are two return values named `output1` and `output2`, you can omit their names and use their type only. -- If there is only one return value and you omitted the name, you don't need brackets for the return values. -- If the function doesn't have return values, you can omit the return parameters altogether. -- If the function has return values, you have to use the `return` statement somewhere in the body of the function. +Yukarıdaki örnekten tahmin edebileceğiniz üzere aşağıda açıklamaları bulunur. -Let's see one practical example. (calculate maximum value) +- `funcName` adlı foonksiyonu tanımlamak için `func` terimini kullanın. +- Fonksiyonlar sıfır veya daha fazla parametreye sahip olabilir. Parametrenin türü adından sonra gelir ve birden fazla parametre varsa `,` ile ayrılır. +- Fonksiyonlar birden fazla değer döndürebilirler. +- Bu örnekte `output1` ve `output2` adında iki değer döndürülmüş. Bunlara ad vermek zorunda değilsiniz, türünü yazmanız yeterli. +- Eğer sadece bir değer döndürecekseniz parantez olmadan yazmalısınız. +- Eğer en az bir değer döndürüyorsanız, fonksiyonun içinde istediğiniz yerde `return` terimini kullanmalısınız. + +Şimdi pratik bir örnek görelim. (Maksimum değerini hesaplama) package main import "fmt" @@ -223,7 +222,7 @@ Let's see one practical example. (calculate maximum value) fmt.Printf("max(%d, %d) = %d\n", y, z, max(y,z)) // call function here } -In the above example, there are two arguments in the function `max`, their types are both `int` so the first type can be omitted. For instance, `a, b int` instead of `a int, b int`. The same rules apply for additional arguments. Notice here that `max` only has one return value, so we only need to write the type of its return value -this is the short form of writing it. +Yukarıdaki örnek fonksiyon `max` da iki aynı tür parametre `int` olduğu için bir tane yazmak yeterli olur. Yani `a int, b int` yerine `a, b int` kullanılır. Birden fazla parametre için de aynı kural geçerlidir. Farkettiyseniz `max` fonksiyonu sadece bir değer döndürür ve zorunda olmadığımız için o değere bir isim vermedik, bu kısa halini kullandık. ### Multi-value return