Skip to playerSkip to main contentSkip to footer
  • 5/20/2025
A nested loop in Python refers to placing one loop inside another. The inner loop executes completely for each iteration of the outer loop. This structure is useful for tasks that require iterating over multiple dimensions or levels of data.

Category

📚
Learning
Transcript
00:00In this lecture, we talk about nested for loop.
00:02Nested for loop is not a basic fault.
00:05For loop is called nested for loop.
00:08For example, if I want to return the list1 item,
00:12we have seen that for x is a variable.
00:15This can be possible, this can be possible,
00:17this can be possible, this can be possible,
00:19this can be possible, this can be possible.
00:21But I will put x in list1.
00:23By the way, when I say anything,
00:25this means that you have no idea
00:27I mean, variable should be understandable.
00:32But I am saying that this is a variable.
00:35If I want to return the list1 item,
00:38then I will print x.
00:41And you see, 1, 2, 3.
00:43If I want to return the list2 item,
00:47then I will print y.
00:52What if my requirement is that,
01:05that I want to print all the elements of list2?
01:12That is my requirement.
01:14And I will give you a practical example.
01:17But you can understand it.
01:19For one, I want to print all the elements.
01:23For two, I want to print all the elements.
01:25For three, I want to nest two loops.
01:29How can I nest two loops?
01:30This is a very easy way.
01:32Because I know that this block of code,
01:37this block of code,
01:39for first loop throughout this loop,
01:43the block of code will be run.
01:45and the elements will run?
01:46And the elements will be run.
01:48The two elements are in elements.
01:50So three elements will try to print.
01:51So three times run.
01:52If this is run.
01:53Therefore, the individual element will be run.
01:58I will basically prepare
01:59all the elements to be run.
02:01From the list2 look模vel.
02:03The two elements will run.
02:05first, first, first element is equal to 1,
02:21Now, I can use this value to this value, or discard this value and then I can use this value.
02:30Let's say, how many times this is happening?
02:32How many times this is happening?
02:332 plus 2.
02:35And it will work.
02:37With no problem.
02:38I can understand this value.
02:41Either you can use this value,
02:43or you can run this value.
02:45I can run this value.
02:47I can run this value.
02:49So, this value has been run.
02:51With no problem.
02:52This value run.
02:54And the value is printed.
02:58So, I can remove this value.
03:01If I remove this value,
03:03you can see the difference.
03:04I can remove this value.
03:06Sorry, I can remove this value.
03:09So, this value is run.
03:11Then I can remove this value.
03:13Then I can use this value.
03:15I can use.
03:16So, how many times this value can be run this value?
03:18So, I can use this value value.
03:20Very good.
03:21Excellent.
03:22Now, I can use this value.
03:24It's not so good to work.
03:25So, I can use this value value for this value value.
03:26So, I can run this value value.
03:28For example, I can use this value value value value value.
03:30I can run.
03:31So, for x's first value, I want to work all the for loops for this list.
03:39Now, if I go here and print the y's, let me leave the x.
03:46Now, this is the 3rd value.
03:49For the first value, the whole code is run.
03:53For the second value, the whole code is run.
03:56For the third value, the whole code is run.
03:59And when I run, the whole code is run.
04:02For the first value of x, it's a block of code is run.
04:05And it's a new for loop.
04:07For the first value of x, I will print both sides by side.
04:20As you see, 1a, 1b, 1c.
04:24And then it goes to 2.
04:26Because when this loop is finished,
04:29Then, this value of x's new value was passed.
04:34And then, he asked us what to do.
04:36He asked what to do.
04:37He asked what to do.
04:38He asked what to do.
04:39He asked who?
04:40It was 2.
04:41Then, he asked what to do.
04:43So, 2a, 2b, 2c.
04:44Okay.
04:45Good.
04:46Good.
04:47Good.
04:48He asked what to do.
04:49That value of x as if the parts have sat and knocked it.
04:51Where all the values are are?
04:52It said that 3.
04:53It said that 3.
04:55It's 3 top где.
04:57And then, I asked, subpro
05:01Basically, you can use two loops.
05:03This is a practical application.
05:06You have to generate two tables.
05:10Generate table of two.
05:15Two tables.
05:16In school, there are 1-2-2-2-4.
05:19If you go to English school,
05:22I have to study English school.
05:25Basically, 1-2-2-3.
05:28And 2-2-2-4-2-4-2-4-2-3-6-4-8.
05:35Let's generate table.

Recommended