lundi 20 novembre 2017

combined if and for loop in python

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

Aucun commentaire:

Enregistrer un commentaire