Site hosted by Angelfire.com: Build your free website today!

 

Programming with S-plus :

 

> AppStat <- c("Stat","Math","Econ","Bio")
> for(subj in AppStat) {print (subj)}
[1] "Stat"
[1] "Math"
[1] "Econ"
[1] "Bio"

> # Calculating the sum of positive integers untill it gets larger than 1000
># a) using while loop :
> n <- 0
> m <- 0
> while(m <= 1000)
+ {
+ n <- n+1
+ m <- m+n
+ }
># b) using repeat loop :
> n <- 0
> m <- 0
> repeat
+ {
+ n <- n+1
+ m <- m+n
+ if (m > 1000) break
+ }

Back to Index page