Estructura de decisión

if (x > 3) { 
  y <- 10
} else { 
  y <- 0
}

El resultado se puede llevar a una variable

y <- if (x > 3) { 10 } else { 0 }

Estructuras de repetición

for (i in 1:10) {
  print(i)
}    
x <- c("a", "b", "c", "d")
for (i in 1:6) {
  print(x[i])
}
       
for (i in seq_along(x)) {
  print(x[i])      
}

for (letter in x) {
  print(letter)
}
(x <- matrix(1:6, 2, 3))

for (i in seq_len(ncol(x))) {
  print(x[i])
}  

for (i in seq_len(nrow(x))) {             
  for (j in seq_len(ncol(x))) {
    print(x[i,j])
  }
}
count <- 0
while (count < 10) {
 print(count)
 count <- count + 1
}

z <- 5
while (z >= 3 && z <= 10) {
  print(z)
  coin <- rbinom(1,1,0.5)
  if (coin == 1) {
    z <- z + 1
  } else {
    z <- z - 1        
  }   
}


x0 <- 1
tol <- 1e-8
repeat {
  x1 <- computeEstimate()
  if (abs(x1 - x0) < tol) {
    break
  } else {
    x0 <- x1
  }
}