FAQ: Loops - Putting it All Together

One last thing I should mention about the increment/decrement operators. They have two operation modes…

prefix   =>  ++i

postfix  =>  i++

I’ll leave you to play around and see their difference. Remember, the operation takes place immediately.

i = 0
while (i < 10) {
    console.log(++i)    // increment before logging
}
1
2
3
4
5
6
7
8
9
10
i = 0
while (i < 10) {
    console.log(i++)   // increment after logging
}
0
1
2
3
4
5
6
7
8
9
1 Like

Oh wow, this is very interesting !! Again, I am extremely grateful !!! Writing this down in my notes, I will practice & explore to better understand. Very helpful, just opened up my mind further to these awesome operators.

1 Like

can someone explain to me what i++ means?

1 Like

https://duckduckgo.com/?q=mdn+operators

1 Like

Hey, I’m confused. Why the ‘i++’ was placed at the top of the ‘For loop’ and at the bottom of the ‘while loop’ ?? Plz help!!!

1 Like

thanks this clarified!

I am confused on this question If anyone is out their to help.followed
for(i=0;i<10;i++){
placeTile(‘mint’)
placeTile(‘orange’)
placeTile(‘mint’)
nothing happens when run any help