标签:style blog color 使用 sp div 问题 log as
问题如本文题目:
如果i==1,则变成2;
如果i==2,则变成1。
通常最容易想到的办法如下:
if(i==1) i = 2; else if(i==2) i = 1;
但是有没有一种更简洁的办法呢?今天无意间看到如下方法:
i = (i==1) + 1;
只用一句话就搞定了,而且使用了逻辑表达式的返回值,很巧妙!
标签:style blog color 使用 sp div 问题 log as
原文地址:http://www.cnblogs.com/huayang/p/4078088.html