184 Statistics and Data Analysis for Microarrays Using R and Bioconductor
Answer:
The first snippet will generate an err or message on line 5. R will complain
about a syntax error caused by “an unexpected ELSE in ’ else’”.
This is caused by the fact that at the end of line 4, R has a syntactically
complete if statement that can and will be executed. The subsequent line
starting with “else” will be conside red a new statement and generate a
syntax error message since no statement starts with else. In the sec ond
snippet of code, this does not happen because only the very last end of
line corresponds to a sy ntactically complete statement.
2. Consider the following piece of code:
> sum = 0
> values = c(1,2,3,4,5)
> for( i in values ) {
+ sum=sum+i
+ print