how to exit from a nested loop in python

DL Neil PythonList at DancesWithMice.info
Sat Feb 9 17:59:35 EST 2019


On 8/02/19 7:45 PM, Kaka wrote:
> for i  in range(len(A.hp)):
> 
>          for j in range(len(run_parameters.bits_Mod)):
>           req_slots[j] = math.ceil((A.T[i])
> 
>           for g in Temp[i]["Available_ranges"][j]:
>            for s in range(g[0], g[-1]):
>                if (s+req_slots[j]-1) <= g[-1]:
>                   if (Temp[i]['cost'][j] <= (run_parameters.PSD):  ------ When this condition is true i want to break the nested loop and start from the begining
>                     served_count +=1
>                     A.T[i]["First_index"]= s
>                     A.T[i]["Last_index"]= s+req_slots[j]-1
>                     A.T[i]["Status"]= 1
>                     A.T[i]["Selected_MOD"] = j
>                     break
> 
> I have this code. When the last "if" condition is satisfied, i want to break all the loops and start the nested loop for next i. else, the loop should continue.


Put the nest inside a try...except block and raise an exception
(illustrated in many web refs)

-- 
Regards =dn



More information about the Python-list mailing list