So I'm trying to decide which of these is more efficient, or if there is a difference between them. The program I'm writing iterates through a for loop (python) and does some stuff, and then, depending on a flag, will write to a file.
Example A:
for element in list:
Do stuff
if(write_to_file):
write to file
Vs example B:
for element in list:
Do stuff
if(write_to_file):
for element in list:
write to file
In the case of A it has to check every time if it's true, but in the case of B if it is true it has to then re-do the for loop. My thought is that they're equal, but I'd like opinions of more experienced programmers