重复循环

R 金融中级

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

循环

ch3_vid1_slides.003.png

1 tdfitness,《My Daily Routine》
R 金融中级

循环

ch3_vid1_slides.004.png

1 tdfitness,《My Daily Routine》 2 John Rochelle,《Water Cycle》
R 金融中级

repeat 循环

i <- 0

repeat {
  i <- i + 1
  print(i)
}
1
2
3
4
.
.
.
# Infinite loop!
R 金融中级

repeat 循环

i <- 0

repeat {
  i <- i + 1
  print(i)

  if(i == 3) {
    break
  }
}
1
2
3
R 金融中级

反复检查股价

stock_price <- 52.1
repeat {
  stock_price <- stock_price * runif(1, .99, 1.01)
  print(stock_price)
  if(stock_price > 52.5) {
    print("Stock price is above 52.5! Sell!")
    break
  }
}
52.0491
52.42412
51.92386
51.82161
52.19669
52.43577
52.71329
"Stock price is above 52.5! Sell!"
R 金融中级

Passons à la pratique !

R 金融中级

Preparing Video For Download...