Let's say I'm inside a for
loop, iterating through a large generator object (e.g. range
). I come across a sequence of values I want to skip, moving several iterations ahead, but for whatever reason I don't know about continue
. I decide to simply increment my loop variable by 5 inside the loop body after checking if it meets a certain condition. Will this work? Why or why not?
I have a matrix, and to iterate through it I use nested for
loops. In doing so, I check the value at each matrix element, looking for a specific match. If the match is found, I execute a break
statement:
matrix = [ ... ]
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if matrix[i][j] == some_value:
break
What happens?