0
loop JS for
What is the difference function main() { var depth = parseInt(readLine(), 10); var a=7 var day=1 for(;a<depth;a+=7,day++){ a-=2 } console.log(day) with function main() { var depth = parseInt(readLine(), 10); var a=7 var day=1 for(;a<=depth;a+=7,day++){ a-=2 } console.log(day) First output 6 Second output 9 Why???
1 Answer
+ 2
Initial value of a is 7 here.
Now if user enters 10 as input to depth variable then with only "<" it will run only 3 times(7,8,9 - 10<10 is false) and with "<=" it will run 4 times(7,8,9,10)