-2

I'm absolutely new to coding. I'm doing a course and was following all steps but there is something I couldn't figure out.

This is the first code that I wrote. It prints 5 times "Hello".

For loop

I tried to change the code. Instead of writing i + 1, I wrote i++, as the instructor told. It again should have printed 5 times "Hello", but it runs infinitely.

For loop

What am I doing wrong? Thanks in advance.

Taslim Oseni
  • 5,420
  • 10
  • 39
  • 64
Guy Caspi
  • 23
  • 2

1 Answers1

3

i = i++ assigns the value of i before the increment i.e. for i = 0 after i = i++ it will still be equal to 0.
You never increment i and thereby never leave the loop.

Turamarth
  • 2,166
  • 4
  • 27
  • 27