Hi I am new to R and Python, just trying to understand why the below code is not giving infinite value:
in R :
for (i in 1:10) {
print(i)
i=5
}
Result:
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
in Python:
for i in range(10):
print(i)
i = 5
Result:
0
1
2
3
4
5
6
7
8
9
As we are setting the value after each iteration of i to 5, it should go into infinite loop. Please help me to understand.
Thanks in advance. Ashish