I am programming in python at the moment, but I have a general programming question.
I have a IF statement and depending on which if I need to use a for loop and some commands or I just need the commands without the for loop. Now, I can just copy my code, but I was wondering if it is possible to go into the for loop?
I'll give my example:
if counter == 0:
for measurement in measlist: #here I work with a list and I need to loop through this list
command 1
elif counter ==1: #here I don't have a list so i cannot walk through the list
command 1
My command 1 is a lot of code, so it would be nice if I don't need to copy it but I can reuse it.
tx
command
a function?counter != 0
and then process the list you have regardless. It will only perform one iteration if your list only contains one element, but that's obviously fine. If whatever produced the list will always produce a list, perhaps you will find that the rest of your code becomes simpler and more straightforward.