iiiiiiiiiii
if (i==4) {
out=x.out; } else #else放这行...无语
{
out=cbind(out,x.out); }
如果写成
if (i==4) {
out=x.out; }
else {
out=cbind(out,x.out); }
就会出错,奇了怪了。
我运行这段代码:
for (i in 1:3) {
x=wt_pcf[,i];
if (i==1) {
wt_pcf.out=x.out;
} else
{
wt_pcf.out=cbind(wt_pcf.out,x.out; ###########
}
}
我没看出来哪有问题,可运行到#########后出错:
错误: 意外的';'在";"里
> }
错误: 意外的'}'在" }"里
这是为什么啊? {}和if else的位置还有关系吗?
荟^_^
?if
Details:
Note that it is a common mistake to forget to put braces ({ .. }) around your statements, e.g., after if(..) or for(....). In particular, you should not have a newline between } and else to avoid a syntax error in entering a if ... else construct at the keyboard or via source. For that reason, one (somewhat extreme) attitude of defensive programming is to always use braces, e.g., for if clauses.
koble
Note that it is a common mistake to forget to put braces ({ .. }) around your statements, e.g., after if(..) or for(....). In particular, you should not have a newline between } and else to avoid a syntax error in entering a if ... else construct at the keyboard or via source. For that reason, one (somewhat extreme) attitude of defensive programming is to always use braces, e.g., for if clauses.
在}和else之间不能有新的行(也就是}和if要在一行)写成
if (con) {
expr
} else {
alt.expr
}
我觉得是比较规范的写法,也易于阅读。
我又试过,如果是没有大括号{}的简单表达式,如:if(con) expr else alt.expr , expr也不能和else放在不同行