Professional Documents
Culture Documents
Administrator Remarks: Quiz 11 - Section 1 #0000002538 - On May 4, 2017 15:48
Administrator Remarks: Quiz 11 - Section 1 #0000002538 - On May 4, 2017 15:48
StudentID
Email
Which array will be the
output when the code
below is excuted?
i <- 1
rand.vec <-
vector()
repeat {
rand.num <-
rnorm(1)
if(rand.num > 0)
{
rand.vec<-
c(rand.vec,rand.num
)
i <- i + 1
}
if(i ==
101){break}
}
par(mfcol = c(2,2))
plot(rand.vec)
hist(rand.vec)
par(mfrow = c(1,1))
What is the output of the
following code? [1] 2
i <- 0 [1] 4
j <- 1 [1] 6
vector <- [1] 8
c(1,2,1,2,1,2,1,2,1
)
while(j<=9) { [1] 3
i <- i + [1] 6
vector[j] * [1] 9
vector[j+1] [1] 12
j <- j+1
print(i) [1] 2
if(j == 5) { [1] 4
break [1] 6
} [1] 8
next [1] 10
print(j)
}
[1] 3
[1] 2
[1] 6
[1] 3
[1] 9
[1] 4
[1] 12
Which one of the Repeat loops are used whenever we don?t have a condition to test.
followings is correct?
You can use break for 'for loops'.
[1] 5
[1] 4
[1] 3
[1] 2
[1] 1
[1] 3
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5