Perulangan while

R Tingkat Menengah untuk Keuangan

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Perulangan while

i <- 0
while(i < 3) {
    print(i)
    i <- i + 1
}
0
1
2
R Tingkat Menengah untuk Keuangan

Periksa saat benar

stock_price <- 52.1
while(stock_price <= 52.5) {
  stock_price <- stock_price * runif(1, .99, 1.01)
  print(stock_price)
}

print("Stock price is above 52.5! Sell!")
52.01159
52.46679
52.00211
52.48659
52.99241
"Stock price is above 52.5! Sell!"
R Tingkat Menengah untuk Keuangan

Ayo berlatih!

R Tingkat Menengah untuk Keuangan

Preparing Video For Download...