/** * nth element in the fibonacci series. * @param n >= 0 * @return the nth element, >= 0. */ functionfib(n) { var a = 1, b = 1; var tmp; while (--n >= 0) { tmp = a; a += b; b = tmp; } return a; }
document.write(fib(10));
10、流程图
1 2 3 4 5 6 7 8 9 10
st=>start: Start:>https://www.zybuluo.com io=>inputoutput: verification op=>operation: Your Operation cond=>condition: Yes or No? sub=>subroutine: Your Subroutine e=>end