repeat 迴圈

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 金融中級

一起來練習吧!

R 金融中級

Preparing Video For Download...