0
[About for loop ]Why different statements but same results?
PROBLEM "Repetition is the mother of learning, the father of action, which makes it the architect of accomplishment." - Zig Ziglar. Inspired by these words, let's create a little program that will output an expression which is given as input, 3 times. Task Complete the code to output the given expression 3 times. Sample Input Learning is fun! Sample Output Learning is fun! Learning is fun! Learning is fun! -------------------------------------------------------------------------------- MY CODE var expression = readLine(); //your code goes here for(var i=0; i<=3; i++){ console.log(expression) } Why it prints "Learning is fun!" 4 times instead of 3? when my statement is i<=3? pls help, many thanks!
3 Answers
+ 3
Simba i < 3
i = 0, 1, 2 -> 3 iterations
+ 7
For i <= 3
i = 0,1,2,3 means 4 iterations
but, i < 3
i = 0,1,2 -> 3iterations
+ 3
Wow, I got it, very helpful, thanks.đ