The control flow would be the same in your specific example. If the code remained unchanged, there'd be no difference. It might even compile down to the same byte-code.
The elif
version states your intent more clearly, however. You're telling whomever reads the code that you expect to find key
in status_msg
, and if it's not there, you expect to find it in error_msg
. To me it appears that other parts of your code will only populate error_msg
when status_msg
is not populated.
The continue
version leaves things more ambiguous. Is error_msg
populated in every case? The continue
version is also less future-proof: what if you want to do something else after printing, regardless of where key
is found? If you consider this code:
for key in inputs:
if key in status_msg.keys():
print status_msg[keys]
continue
if key in error_msg.keys():
print error_msg[key]
do_something()
Then do_something()
is only executed when key
is not in status_msg
. The conditionals are asymmetrical; one aborts the iteration and the other lets control flow out to the rest of the block. That might not be obvious to someone approaching the code later, especially if the conditionals contain more complex logic/more lines.
I think the elif
version is superior: it's future-proof, states your intent, and is symmetrical. The performance is probably identical, and even if it's not, it's nominally different and irrelevant.