As I know, “continue” will jump back to the top of the loop. But in my case it’s not jumping back, continue don’t like me 🙁
for cases in files:
if ('python' in cases.split()):
execute_python_scripts(cases.split())
elif run_test_case(cases.split()):
continue
else:
logger("I am here")
break
In my case run_test_case() gives 1, 2, 3, 4 etc… But it always performs first(1) and jump to the else part. So I am getting the “I am here” message. It should not work like this. As I am using “continue”, it should jump to the for loop.
Following is the run_test_case():
def run_test_case(job):
for x in job:
num_of_cases = num_of_cases - 1
test_type = x.split('/')
logger(log_file,"Currently "+ x +"hai!!")
if test_type[0] == 'volume':
backdoor = test_type[1].split("_")
if backdoor[0] == 'backdoor':
return get_all_nas_logs()
else:
if perform_volume_operations(x,num_of_cases) == False:
return False
else:
logger(log_file,"wrong ha!!")
Why is it always going to the else part, without jumping back to the for loop? Thanks in advance.
Here
elif run_test_case(cases.split()):you are calling therun_test_casemethod, that will run your code to evaluate the result for theelifcondition.It only enters the block delimited by
elif(in your case,continue), if the result of that method evaluates toTrue, otherwise it will jump to the else clause.The problem is probably in your
run_test_casecode, that is never returning True, and so you’ll never get the behavior that you’re expecting.It’s hard to say without knowing exactly what you want to accomplish, but I’d say that you’re missing a
return Truein the end of that code, meaning, if everything executes correctly right until the end, you want it to return True… but I’m only guessing here, you need to think about what that method is supposed to do.In python an
iforelifclause is evaluated for not only theTrueandFalseconstants, but more generally for True-like and False-like values.None, for instance, is a false-like value, a non-empty string is a true-like value, etc.Check this from the documentation on values that are considered true or false:
http://docs.python.org/library/stdtypes.html