Variable declaration reset: Difference between revisions
Content added Content deleted
(→{{header|Java}}: added unitialised comment/error) |
|||
Line 294: | Line 294: | ||
EOF</lang> |
EOF</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
|||
2 |
|||
5 |
|||
</pre> |
|||
=={{header|Python}}== |
|||
In Python, variables are supposed to be defined before they are used, but the undefined variable `prev` is still not equal to `curr` below, so the code runs nevertheless. Note that a Python code checker such as pyflakes will flag such code. |
|||
<lang python> |
|||
s = [1, 2, 2, 3, 4, 4, 5] |
|||
for i in range(len(s)): |
|||
curr = s[i] |
|||
if i > 0 and curr == prev: |
|||
print(i) |
|||
prev = curr |
|||
</lang>{{out}} |
|||
<pre> |
<pre> |
||
2 |
2 |