this is called nested loops. the first one is outer loop and and the insert one is inner loop, so when outer loop run once then the inner loop gotta finish his job from 0 to whatever it has to run to end with and then when the inner loop is done then the outer loop goes again. So, basically it is a loop inside a loop so when the first one run then the second one has to finish his job then the first will run again and then second has to finish his run and so on. i hope u got it. ye cant use one loop because we have to go first test then second test then so on.
You can also swap a two variable in python like this:
arr[j], arr[j+1] = arr[j+1], arr[j]
in second loop putting (len(list1)-i -1), will save iterations.
why did we use the first for loop? why did not we use only one loop?
I want to understant it too...
this is called nested loops. the first one is outer loop and and the insert one is inner loop, so when outer loop run once then the inner loop gotta finish his job from 0 to whatever it has to run to end with and then when the inner loop is done then the outer loop goes again. So, basically it is a loop inside a loop so when the first one run then the second one has to finish his job then the first will run again and then second has to finish his run and so on. i hope u got it. ye cant use one loop because we have to go first test then second test then so on.
@@HungryBen-d7ythanks
@@3thrisha869 your welcome
i dont understand explain better pls
what part you dont understand i will explain