Koşullu İfadeler

Orta Düzey R

Filip Schouwenaars

DataCamp Instructor

if ifadesi

if(condition) {
  expr
}
x <- -3
if(x < 0) {
  print("x negatif bir sayı")
}
"x negatif bir sayı"
Orta Düzey R

if ifadesi

if(condition) {
  expr
}
x <- 5
if(x < 0) {
  print("x negatif bir sayı")
}
  • Çıktı yok
Orta Düzey R

else ifadesi

if(condition) {
  expr1
} else {
  expr2
}
x <- -3
if(x < 0) {
  print("x negatif bir sayı")
} else {
  print("x pozitif veya sıfır")
}
"x negatif bir sayı"
Orta Düzey R

else ifadesi

if(condition) {
  expr1
} else {
  expr2
}
x <- 5
if(x < 0) {
  print("x negatif bir sayı")
} else {
  print("x pozitif veya sıfır")
}
"x pozitif veya sıfır"
Orta Düzey R

else if ifadesi

if(condition1) {
  expr1
} else if(condition2) {
  expr2
} else {
  expr3
}
Orta Düzey R

else if ifadesi

x <- -3
if(x < 0) {
  print("x negatif bir sayı")
} else if(x == 0) {
  print("x sıfır")
} else {
  print("x pozitif bir sayı")
}
"x negatif bir sayı"
Orta Düzey R

else if ifadesi

x <- 0
if(x < 0) {
  print("x negatif bir sayı")
} else if(x == 0) {
  print("x sıfır")
} else {
  print("x pozitif bir sayı")
}
"x sıfır"
Orta Düzey R

else if ifadesi

x <- 5
if(x < 0) {
  print("x negatif bir sayı")
} else if(x == 0) {
  print("x sıfır")
} else {
  print("x pozitif bir sayı")
} 
"x pozitif bir sayı"
Orta Düzey R

if, else if, else

x <- 6
if(x %% 2 == 0) {
  print("2'ye tam bölünür")
} else if(x %% 3 == 0) {
  print("3'e tam bölünür")
} else {
  print("ne 2'ye ne 3'e bölünür...")
}
"2'ye tam bölünür"
Orta Düzey R

Hadi pratik yapalım!

Orta Düzey R

Preparing Video For Download...