I have the following loop which works when creating an output file. There are n-number of rows and 24 columns and it’s going each row and column to create plots. variable below is from index [3:24]. Now the variable is created somewhere in before this loop in the code that I don’t want to touch. I want to be able to overwrite the variable and not go over some of the indexes from [3:24] such as index 22, 20, 3. How can I implement that below? I tried creating another if statement so that when it reaches index 20 it would break. Anyways my solution doesn’t work so I was hoping to get an answer here. Thanks!
for row in range(len(self.CSVResult)):
if (abs(self.CSVResult[row][variable-1]) < 1.2E20):
skipsw = 1
break
For example, variable is looping from index 3 to 24, once it reaches index 22 it will skip and continue to 21. Then once it reaches index 20 it will skip and reach 19. Until it reach index 3 again and then skip that value too.
>Solution :
Does something like this help?
skip_values = [22, 21, 3]
for row in range(len(self.CSVResult)):
if variable in skip_values:
continue
elif (abs(self.CSVResult[row][variable-1]) < 1.2E20):
skipsw = 1
break
If I understood correctly, you want to define some ‘skip values’, where if variable is equal one of those, then it does not do the rest of the code.