System.out.println("top->down");
int n = 999;
for (int i = n; i >= 0; i--) {
n++;
System.out.println("i = " + i + "\t n = " + n);
}
System.out.println("bottom->up");
n = 1;
for (int i = 0; i < n; i++) {
n++;
System.out.println("i = " + i + "\t n = " + n);
}
我敢打赌,大多数程序员阅读(i = 0; i < N; i + +)并立即理解这个循环 N 次。一个(i = 1; i < = N; i + +)的循环,对我来说,就不那么清晰了,而且对于(i = N; i > 0; i ——) ,我必须思考一会儿。如果代码的意图直接进入大脑而不需要任何思考,那是最好的。
ldw r2,-3340(fp) %load i to r2
addi r2,r2,1 %increase i by 1
stw r2,-3340(fp) %save value of i
ldw r2,-3340(fp) %load value again (???)
cmplti r2,r2,100 %compare if less than equal 100
bne r2,zero,0xa018 %jump