title
9. For loop [Python 3 Programming Tutorials]
description
The topic which I will explain to you today is about “for statement” also known as “loop statement”, “for” loop, “while statement”, how to create “for” loop, why “for” loop is used.
Exercise: https://github.com/codebasics/py/blob/master/Basics/Exercise/9_for/9_for_exercise.md
Topics that are covered in this Video:
0:00 Overview
2:55 Create a for loop (Syntax of for loop)
6:53 Why for loop is used?
7:02 Use of range() function
18:51 While statement
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
🔖Hashtags🔖
#forloopinpython #pythonforloop #tutorial #loopinpython #python #pythonloops #pythonloops
Next Video:
10. Functions [Python 3 Programming Tutorials]: https://www.youtube.com/watch?v=fz_BCnhEQYQ&list=PLeo1K3hjS3uv5U-Lmlnucd7gqF-3ehIh0&index=11
Website: https://codebasics.io/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
detail
{'title': '9. For loop [Python 3 Programming Tutorials]', 'heatmap': [{'end': 175.092, 'start': 160.485, 'weight': 0.783}, {'end': 451.119, 'start': 421.352, 'weight': 0.999}, {'end': 627.884, 'start': 545.912, 'weight': 0.822}, {'end': 1035.891, 'start': 1013.504, 'weight': 0.714}, {'end': 1127.959, 'start': 1091.671, 'weight': 0.814}, {'end': 1168.509, 'start': 1128.976, 'weight': 0.907}], 'summary': "Learn python for loop to calculate total monthly expenses, with examples for january ($2340), february ($2500), march ($2100), april ($3100), and may ($2980). discover the traditional method of calculating total expenses and its inefficiency, and how for loops provide a more concise and readable code. explore the usage of for loop and range function for operations, 'break' in loop termination, and the 'continue' statement to skip specific items in python.", 'chapters': [{'end': 89.135, 'segs': [{'end': 89.135, 'src': 'embed', 'start': 28.759, 'weight': 0, 'content': [{'end': 39.411, 'text': 'So for January, February, each of these months, you have your total expense amount and you want to calculate the total of all these monthly expenses.', 'start': 28.759, 'duration': 10.652}, {'end': 42.753, 'text': 'So how do you solve this problem in Python?', 'start': 40.572, 'duration': 2.181}, {'end': 48.754, 'text': 'You want to use Python to track down your monthly expenses, and Python program should tell you the total result.', 'start': 42.813, 'duration': 5.941}, {'end': 56.556, 'text': 'So for that, first you need to create a list and we are going to call it exp equal to.', 'start': 49.374, 'duration': 7.182}, {'end': 58.416, 'text': 'I will create a list.', 'start': 57.736, 'duration': 0.68}, {'end': 61.857, 'text': "This is how you create a list and you're going to store all your monthly expenses.", 'start': 58.436, 'duration': 3.421}, {'end': 66.943, 'text': "So let's say in January you spend $2340.", 'start': 61.917, 'duration': 5.026}, {'end': 70.545, 'text': 'Your February expense was $2, 500.', 'start': 66.943, 'duration': 3.602}, {'end': 72.227, 'text': 'Your March expense was $2, 100.', 'start': 70.546, 'duration': 1.681}, {'end': 80.054, 'text': "Your April expense was $3, 100 because it's your marriage anniversary.", 'start': 72.227, 'duration': 7.827}, {'end': 81.715, 'text': 'You have a big expense.', 'start': 80.835, 'duration': 0.88}, {'end': 89.135, 'text': 'And your May expense is $2, 980.', 'start': 83.056, 'duration': 6.079}], 'summary': 'Track monthly expenses in python with total result.', 'duration': 60.376, 'max_score': 28.759, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY28759.jpg'}], 'start': 0.609, 'title': 'Using python for monthly expenses', 'summary': 'Discusses using python for loop to calculate total monthly expenses with examples: january ($2340), february ($2500), march ($2100), april ($3100), and may ($2980).', 'chapters': [{'end': 89.135, 'start': 0.609, 'title': 'Python for loop and monthly expenses', 'summary': 'Discusses the usage of for loop in python to calculate the total monthly expenses by creating a list of expenses and iterating through it, with examples including january ($2340), february ($2500), march ($2100), april ($3100), and may ($2980).', 'duration': 88.526, 'highlights': ['The chapter explains the usage of for loop in Python to calculate the total monthly expenses by creating a list of expenses and iterating through it.', 'It provides examples of monthly expenses including January ($2340), February ($2500), March ($2100), April ($3100), and May ($2980).', 'The examples demonstrate the practical application of for loop in tracking and totaling monthly expenses.']}], 'duration': 88.526, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY609.jpg', 'highlights': ['The examples demonstrate the practical application of for loop in tracking and totaling monthly expenses.', 'The chapter explains the usage of for loop in Python to calculate the total monthly expenses by creating a list of expenses and iterating through it.', 'It provides examples of monthly expenses including January ($2340), February ($2500), March ($2100), April ($3100), and May ($2980).']}, {'end': 410.306, 'segs': [{'end': 151.482, 'src': 'embed', 'start': 114.763, 'weight': 0, 'content': [{'end': 116.525, 'text': "So I'm interested in executing four.", 'start': 114.763, 'duration': 1.762}, {'end': 124.571, 'text': 'So it is telling me 13, 020 is the total expense from 1 January all the way till May.', 'start': 117.105, 'duration': 7.466}, {'end': 130.833, 'text': 'Now, the problem with this code is that you are writing a long expression here.', 'start': 125.531, 'duration': 5.302}, {'end': 133.735, 'text': 'What if your list had like hundred items in it?', 'start': 130.833, 'duration': 2.902}, {'end': 139.557, 'text': "If you start writing all of these, you'll become granddaddy by the time you done writing it.", 'start': 133.975, 'duration': 5.582}, {'end': 140.898, 'text': "It's like really tedious.", 'start': 139.557, 'duration': 1.341}, {'end': 151.482, 'text': 'So a programming language should have something better and That thing is a for loop So let me now do the same thing using a for loop.', 'start': 141.418, 'duration': 10.064}], 'summary': 'Total expense from 1 jan to may: $13,020. exploring more efficient coding with for loop.', 'duration': 36.719, 'max_score': 114.763, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY114763.jpg'}, {'end': 190.623, 'src': 'heatmap', 'start': 160.485, 'weight': 0.783, 'content': [{'end': 161.966, 'text': 'Or you can just put this character here.', 'start': 160.485, 'duration': 1.481}, {'end': 164.027, 'text': "It means this line won't have any impact.", 'start': 162.206, 'duration': 1.821}, {'end': 172.27, 'text': 'So now you can say total, you can create a total variable and you can say my total expense is zero.', 'start': 164.747, 'duration': 7.523}, {'end': 175.092, 'text': "and now you're going to run a for loop.", 'start': 173.17, 'duration': 1.922}, {'end': 181.477, 'text': 'so the syntax of for loop is this so you can say for item in exp.', 'start': 175.092, 'duration': 6.385}, {'end': 190.623, 'text': "colon, what this means is for is a special keyword, and then you're saying item in exp, meaning for each of the items in exp.", 'start': 181.477, 'duration': 9.146}], 'summary': 'Demonstrating for loop syntax and initializing total expense as zero.', 'duration': 30.138, 'max_score': 160.485, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY160485.jpg'}, {'end': 285.273, 'src': 'embed', 'start': 229.018, 'weight': 1, 'content': [{'end': 240.43, 'text': 'so when you write a for loop internally, computer will expand your code into something which is shown in the diagram here.', 'start': 229.018, 'duration': 11.412}, {'end': 250.28, 'text': 'so as you see in the diagram, at each iteration it is taking each of these individual items and adding them into your total.', 'start': 240.43, 'duration': 9.85}, {'end': 258.137, 'text': "So you don't have to write all the code that is shown in the diagram, but instead the for loop will do that for you.", 'start': 251.252, 'duration': 6.885}, {'end': 262.162, 'text': 'And it makes your code look beautiful and readable.', 'start': 258.639, 'duration': 3.523}, {'end': 266.406, 'text': 'Now let me show you the same thing using pycharm debugger.', 'start': 262.622, 'duration': 3.784}, {'end': 278.59, 'text': 'So if you have seen my pycharm intro on debugging, et cetera, you would have some idea on how to set breakpoints and do debugging.', 'start': 266.926, 'duration': 11.664}, {'end': 283.612, 'text': 'If you have not seen, then I would recommend going back to that video and take a look.', 'start': 278.75, 'duration': 4.862}, {'end': 285.273, 'text': 'So let me set a breakpoint here.', 'start': 283.992, 'duration': 1.281}], 'summary': 'For loop simplifies code, adds items to total. debugger helps in setting breakpoints.', 'duration': 56.255, 'max_score': 229.018, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY229018.jpg'}], 'start': 89.136, 'title': 'Total expense calculation', 'summary': 'Explains the traditional method of calculating total expense using a variable total and highlights its inefficiency due to long expression and tedious effort. it also demonstrates the use of a for loop to calculate the total expense, resulting in a more concise and readable code, and provides a step-by-step explanation of the iteration process and debugging in pycharm.', 'chapters': [{'end': 140.898, 'start': 89.136, 'title': 'Total expense calculation', 'summary': 'Explains traditional method of calculating total expense using a variable total and highlights the inefficiency of this method due to long expression and tedious effort, with an example of 13,020 as total expense from january to may.', 'duration': 51.762, 'highlights': ['The traditional method of calculating total expense using a variable called total and adding individual items results in a total expense of 13,020 from January to May.', 'The inefficiency of the traditional method is highlighted due to the tedious effort and long expression required, especially if the list contains a large number of items.']}, {'end': 410.306, 'start': 141.418, 'title': 'Using for loop to calculate total expense', 'summary': 'Demonstrates the use of a for loop to calculate the total expense by iterating through a list of expenses, resulting in a more concise and readable code. it also showcases the debugging process in pycharm, providing a step-by-step explanation of how the for loop iterates through the list and calculates the total expense.', 'duration': 268.888, 'highlights': ['Using a for loop to iterate through a list of expenses and calculate the total expense, resulting in a more concise and readable code.', 'Demonstrating the step-by-step debugging process in PyCharm, showing how the for loop iterates through the list and calculates the total expense.', 'Explaining the expansion of the code by the computer during the for loop iteration, resulting in a more efficient and readable code.']}], 'duration': 321.17, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY89136.jpg', 'highlights': ['The traditional method results in a total expense of 13,020 from January to May.', 'Using a for loop results in a more concise and readable code.', 'The inefficiency of the traditional method is highlighted due to the tedious effort and long expression required.', 'Demonstrating the step-by-step debugging process in PyCharm for the for loop iteration.']}, {'end': 742.954, 'segs': [{'end': 451.119, 'src': 'heatmap', 'start': 413.728, 'weight': 0, 'content': [{'end': 420.652, 'text': 'So just to summarize, for loop should be used whenever you want to do same operation on a range of things.', 'start': 413.728, 'duration': 6.924}, {'end': 424.374, 'text': 'Okay Next thing I want to cover is a range function.', 'start': 421.352, 'duration': 3.022}, {'end': 430.681, 'text': 'what if you want to print number one to ten?', 'start': 425.916, 'duration': 4.765}, {'end': 432.763, 'text': "so let's do that using for loop.", 'start': 430.681, 'duration': 2.082}, {'end': 436.767, 'text': "so we'll say for i in range.", 'start': 432.763, 'duration': 4.004}, {'end': 445.556, 'text': 'so range is a special function in python and the way it works is you specify two indexes start and stop.', 'start': 436.767, 'duration': 8.789}, {'end': 451.119, 'text': 'so my start index is one and your stop, as it is indicated by the tooltips.', 'start': 445.556, 'duration': 5.563}], 'summary': 'Use for loop for same operation on a range. range function in python specifies start and stop indexes.', 'duration': 31.828, 'max_score': 413.728, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY413728.jpg'}, {'end': 627.884, 'src': 'heatmap', 'start': 508.668, 'weight': 2, 'content': [{'end': 512.852, 'text': 'you can use the same thing to print a square of all these numbers.', 'start': 508.668, 'duration': 4.184}, {'end': 518.655, 'text': 'so you can just say i cross i and this will print square of all the numbers from 1 to 10..', 'start': 512.852, 'duration': 5.803}, {'end': 527.582, 'text': 'so again run and you see 1 4 9 16 and the square of 10 is 100.', 'start': 518.655, 'duration': 8.927}, {'end': 534.186, 'text': 'so whenever you want to do this kind of operation on a range of numbers, you should use range.', 'start': 527.582, 'duration': 6.604}, {'end': 539.509, 'text': "okay, now let's go back to our monthly expense example.", 'start': 534.186, 'duration': 5.323}, {'end': 545.912, 'text': 'so let me create that same variable for the list again.', 'start': 539.509, 'duration': 6.403}, {'end': 553.498, 'text': 'and now what i want to do here is i want to print monthly expense along with the month number.', 'start': 545.912, 'duration': 7.586}, {'end': 557.581, 'text': "so what i'll do is i will use len function.", 'start': 553.498, 'duration': 4.083}, {'end': 566.068, 'text': 'so i will say for i in range, len exp.', 'start': 557.581, 'duration': 8.487}, {'end': 570.972, 'text': 'so what this len will do is it will return the length of this list.', 'start': 566.068, 'duration': 4.904}, {'end': 572.694, 'text': 'so what is the length of the list?', 'start': 570.972, 'duration': 1.722}, {'end': 573.635, 'text': 'it is five.', 'start': 572.694, 'duration': 0.941}, {'end': 582.889, 'text': "so when you say for i in range five, what you're doing is you are omitting the start index and your end index will be the length of the list.", 'start': 573.635, 'duration': 9.254}, {'end': 593.421, 'text': 'so you will say print your month is i plus one.', 'start': 582.889, 'duration': 10.532}, {'end': 594.882, 'text': 'why am i doing i plus one?', 'start': 593.421, 'duration': 1.461}, {'end': 605.09, 'text': "because in the range function i'm specifying only the end index and if i don't specify my start index it will be zero by default.", 'start': 594.882, 'duration': 10.208}, {'end': 608.393, 'text': "so if it is zero, i don't want to start from zero, i want to start from one.", 'start': 605.09, 'duration': 3.303}, {'end': 618.621, 'text': "that's why i'm doing i plus one and i will say my expense is exp of i.", 'start': 608.393, 'duration': 10.228}, {'end': 627.884, 'text': 'so again, expense is a list, so you can use an index in a square bracket to access each individual elements.', 'start': 619.401, 'duration': 8.483}], 'summary': 'Using range and len functions to work with numbers and lists in python, demonstrating printing squares and monthly expenses.', 'duration': 96.422, 'max_score': 508.668, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY508668.jpg'}, {'end': 672.783, 'src': 'embed', 'start': 637.707, 'weight': 1, 'content': [{'end': 644.889, 'text': 'when you say exp1, you are referring to 2500 value and so on.', 'start': 637.707, 'duration': 7.182}, {'end': 652.711, 'text': "also, as we are calculating a total, we'll do the same thing as before create a variable called total,", 'start': 644.889, 'duration': 7.822}, {'end': 661.114, 'text': "and on each iteration you're saying total is total plus exp of i.", 'start': 652.711, 'duration': 8.403}, {'end': 665.12, 'text': "let's run this Awesome.", 'start': 661.114, 'duration': 4.006}, {'end': 669.602, 'text': 'So it is saying month one expenses this, month two expenses this.', 'start': 665.7, 'duration': 3.902}, {'end': 672.002, 'text': 'But hey, we forgot to print total.', 'start': 670.002, 'duration': 2}, {'end': 672.783, 'text': 'So let me do that.', 'start': 672.042, 'duration': 0.741}], 'summary': 'Referring to expenses, calculating total, and printing the result.', 'duration': 35.076, 'max_score': 637.707, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY637707.jpg'}], 'start': 413.728, 'title': 'Python for loop, range function, and expense management', 'summary': 'Covers the usage of python for loop and range function to perform operations on a range of things, including printing numbers and their squares, managing monthly expenses, and utilizing len() and range() functions.', 'chapters': [{'end': 539.509, 'start': 413.728, 'title': 'Python for loop and range function', 'summary': 'Covers the usage of for loop for performing the same operation on a range of things, demonstrating the range function to print numbers from 1 to 10 and their squares using python, emphasizing the utility of the range function for such operations.', 'duration': 125.781, 'highlights': ['The range function in Python is used to specify a range of numbers using start and end indexes, allowing for efficient iteration over the specified range.', "Demonstrating the usage of for loop and the range function, the example showcases the printing of numbers 1 to 10 and their squares, providing a practical illustration of the range function's utility for such operations.", 'The for loop is illustrated as a powerful tool for performing the same operation on a range of elements, emphasizing its relevance for efficient and repetitive tasks in programming.']}, {'end': 605.09, 'start': 539.509, 'title': 'Printing monthly expenses with month numbers', 'summary': 'Explains how to print monthly expenses along with month numbers using the len function to determine the length of the list, which is five, and then using a for loop to iterate through the list and print the month number incremented by one.', 'duration': 65.581, 'highlights': ['Using the len function to determine the length of the list, which is five, to iterate through the list.', 'Using a for loop to iterate through the list and print the month number incremented by one.']}, {'end': 742.954, 'start': 605.09, 'title': 'Managing expenses with python', 'summary': 'Demonstrates using python to manage monthly expenses, iterating through a list to calculate total expenses, and understanding the len() and range() functions.', 'duration': 137.864, 'highlights': ['The chapter covers iterating through a list to calculate total expenses, with an example of accessing individual elements and using a for loop to calculate the total.', 'The explanation of the len() function and its application to determine the number of items in a list is provided, along with the demonstration of the range() function.', 'The use of range() function with two parameters for specifying starting and ending indexes is explained, along with a default assumption if parameters are not specified.']}], 'duration': 329.226, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY413728.jpg', 'highlights': ['The range function in Python is used to specify a range of numbers using start and end indexes, allowing for efficient iteration over the specified range.', 'The chapter covers iterating through a list to calculate total expenses, with an example of accessing individual elements and using a for loop to calculate the total.', 'Using the len function to determine the length of the list, which is five, to iterate through the list.', "Demonstrating the usage of for loop and the range function, the example showcases the printing of numbers 1 to 10 and their squares, providing a practical illustration of the range function's utility for such operations.", 'The for loop is illustrated as a powerful tool for performing the same operation on a range of elements, emphasizing its relevance for efficient and repetitive tasks in programming.', 'Using a for loop to iterate through the list and print the month number incremented by one.', 'The explanation of the len() function and its application to determine the number of items in a list is provided, along with the demonstration of the range() function.', 'The use of range() function with two parameters for specifying starting and ending indexes is explained, along with a default assumption if parameters are not specified.']}, {'end': 976.12, 'segs': [{'end': 894.199, 'src': 'embed', 'start': 794.738, 'weight': 1, 'content': [{'end': 799.22, 'text': 'And once you find the key, what will you do? You will stop your search.', 'start': 794.738, 'duration': 4.482}, {'end': 804.842, 'text': 'So let me demonstrate the same thing using for loop and a break statement.', 'start': 799.76, 'duration': 5.082}, {'end': 811.104, 'text': "So let's say my key location is chair.", 'start': 805.422, 'duration': 5.682}, {'end': 818.107, 'text': "So my keys are actually placed on chair and I don't know where they are, but I know all the locations in my home.", 'start': 811.444, 'duration': 6.663}, {'end': 823.929, 'text': 'So all the locations in my home are garage.', 'start': 818.467, 'duration': 5.462}, {'end': 827.55, 'text': 'Then I have living room.', 'start': 825.269, 'duration': 2.281}, {'end': 833.284, 'text': 'then i have closet and i have chair.', 'start': 829.378, 'duration': 3.906}, {'end': 835.528, 'text': 'so let me put chair here before close it.', 'start': 833.284, 'duration': 2.244}, {'end': 843.622, 'text': "so i'm going to search through my home for my keys in all this location in this particular order.", 'start': 836.877, 'duration': 6.745}, {'end': 850.686, 'text': 'so again you can use for loop, because for loop is used to go through each of these items one by one.', 'start': 843.622, 'duration': 7.064}, {'end': 857.991, 'text': "so you'll say for i in locations, meaning search each of these locations one by one,", 'start': 850.686, 'duration': 7.305}, {'end': 865.323, 'text': 'and if i is equal to this is a comparison operator double equal to sign.', 'start': 857.991, 'duration': 7.332}, {'end': 868.027, 'text': 'if i is equal to key location,', 'start': 865.323, 'duration': 2.704}, {'end': 887.034, 'text': "then you will say print key is found in this particular place right and once the key is found now you don't want to go complete your for loop,", 'start': 868.027, 'duration': 19.007}, {'end': 888.214, 'text': 'you want to break.', 'start': 887.034, 'duration': 1.18}, {'end': 894.199, 'text': 'so when you write this break statement, it will just come out of the for loop, it will just terminate in between.', 'start': 888.214, 'duration': 5.985}], 'summary': 'Using a for loop and a break statement to search for keys in specific locations in a home.', 'duration': 99.461, 'max_score': 794.738, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY794738.jpg'}, {'end': 982.027, 'src': 'embed', 'start': 952.454, 'weight': 0, 'content': [{'end': 955.896, 'text': "Then it's living room and you're saying key is not found in living room.", 'start': 952.454, 'duration': 3.442}, {'end': 958.033, 'text': 'But third comes chair.', 'start': 956.772, 'duration': 1.261}, {'end': 963.695, 'text': 'And since key is on the chair, it will say keys found in chair and it will break.', 'start': 958.433, 'duration': 5.262}, {'end': 964.876, 'text': 'So now see what happens.', 'start': 963.795, 'duration': 1.081}, {'end': 967.457, 'text': 'So you see you came out of the program.', 'start': 965.396, 'duration': 2.061}, {'end': 969.298, 'text': "It didn't go through this thing.", 'start': 967.857, 'duration': 1.441}, {'end': 976.12, 'text': 'This is very useful when you are doing real time programming and you have a list which has less than 10, 000 items.', 'start': 969.678, 'duration': 6.442}, {'end': 982.027, 'text': "You don't want to just go over each of these items because it will waste some of the CPU cycles.", 'start': 976.201, 'duration': 5.826}], 'summary': 'Program breaks when key is found on chair, useful for real-time programming with less than 10,000 items.', 'duration': 29.573, 'max_score': 952.454, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY952454.jpg'}], 'start': 744.454, 'title': "Using 'break' in loop termination", 'summary': "Covers using 'break' in for loops to terminate the search for an item, employing comparison operators and the break statement in python, and its application in real-time programming, with a focus on efficiency in scenarios with fewer than 10,000 items.", 'chapters': [{'end': 857.991, 'start': 744.454, 'title': 'Using for loop to break and terminate', 'summary': 'Explains the concept of using a for loop to iterate through a list of locations to find an item, and how to terminate the loop once the item is found, using a practical example of searching for keys in a home.', 'duration': 113.537, 'highlights': ['Explaining the concept of using a for loop to search through a list of locations to find an item.', 'Demonstrating the use of a break statement to terminate the for loop once the item is found.', 'Illustrating the practical application of the concept with a relatable example of searching for keys in a home.']}, {'end': 925.056, 'start': 857.991, 'title': 'Using comparison operators and break statement in python', 'summary': "Discusses using comparison operators and the break statement in python to search for a key location in a for loop, identifying the key's location and terminating the loop if found, and printing a message if the key is not found, with an illustration of the process.", 'duration': 67.065, 'highlights': ['Using comparison operators to check for the key location and printing messages based on the comparison results.', 'Illustration of using the break statement to terminate the for loop once the key is found.', 'Explanation of printing a message if the key is not found in a specific location.']}, {'end': 976.12, 'start': 925.116, 'title': "Using 'break' in real-time programming", 'summary': "Explains the usage of 'break' in real-time programming to terminate a loop when a specific condition is met, demonstrated through debugging a scenario with a list of items with a key, emphasizing its utility for lists with less than 10,000 items.", 'duration': 51.004, 'highlights': ["The chapter demonstrates using 'break' to terminate a loop when a specific condition is met, making it useful for real-time programming with lists containing less than 10,000 items.", "The example showcases the use of 'break' to stop the iteration once the desired item is found, providing a practical approach to real-time programming.", "The transcript emphasizes using 'break' when the goal is achieved, thereby illustrating its effectiveness in terminating a loop upon meeting a specific condition."]}], 'duration': 231.666, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY744454.jpg', 'highlights': ["The chapter demonstrates using 'break' to terminate a loop when a specific condition is met, making it useful for real-time programming with lists containing less than 10,000 items.", 'Illustration of using the break statement to terminate the for loop once the key is found.', 'Explaining the concept of using a for loop to search through a list of locations to find an item.', 'Using comparison operators to check for the key location and printing messages based on the comparison results.']}, {'end': 1240.131, 'segs': [{'end': 1035.891, 'src': 'heatmap', 'start': 1000.273, 'weight': 0, 'content': [{'end': 1009.421, 'text': 'So when you are running a for loop and doing same operation on list of items, sometimes for some items, you want to skip that operation.', 'start': 1000.273, 'duration': 9.148}, {'end': 1012.723, 'text': 'So in that case, you will use continue.', 'start': 1010.181, 'duration': 2.542}, {'end': 1023.707, 'text': "So again, let's work on a simple problem where between 1 to 5, you want to print the square of all numbers except the even numbers.", 'start': 1013.504, 'duration': 10.203}, {'end': 1025.588, 'text': 'So you want to skip even numbers.', 'start': 1023.827, 'duration': 1.761}, {'end': 1028.569, 'text': 'So you will say for i in range.', 'start': 1025.667, 'duration': 2.902}, {'end': 1035.891, 'text': 'So if you want to go from 1 to 5, you have to say 1 to 6 because it will exclude this second index.', 'start': 1030.489, 'duration': 5.402}], 'summary': 'Using continue statement to skip even numbers when printing squares from 1 to 5.', 'duration': 28.296, 'max_score': 1000.273, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY1000273.jpg'}, {'end': 1085.807, 'src': 'embed', 'start': 1062.051, 'weight': 2, 'content': [{'end': 1070.599, 'text': 'so when you run it, it is printing square of all the numbers between one to five, but you want to skip even numbers, which is this and this.', 'start': 1062.051, 'duration': 8.548}, {'end': 1077.061, 'text': "so for that, this is your main operation that you're doing for loop.", 'start': 1072.478, 'duration': 4.583}, {'end': 1080.944, 'text': 'just before that, just say do the check for even number.', 'start': 1077.061, 'duration': 3.883}, {'end': 1083.005, 'text': 'how do you do a check for even number?', 'start': 1080.944, 'duration': 2.061}, {'end': 1085.807, 'text': 'you say i percentage 2 equal to 0.', 'start': 1083.005, 'duration': 2.802}], 'summary': "Print squares of numbers 1-5, skip even numbers using a for loop and check for even numbers using 'i % 2 == 0'.", 'duration': 23.756, 'max_score': 1062.051, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY1062051.jpg'}, {'end': 1127.959, 'src': 'heatmap', 'start': 1091.671, 'weight': 0.814, 'content': [{'end': 1092.891, 'text': 'so this continue statement.', 'start': 1091.671, 'duration': 1.22}, {'end': 1097.474, 'text': 'what it will do is once you are in if condition, if it is satisfied,', 'start': 1092.891, 'duration': 4.583}, {'end': 1103.779, 'text': 'you will just continue from here and you will jump back here in the for loop for the next iteration.', 'start': 1097.474, 'duration': 6.305}, {'end': 1112.106, 'text': 'Hence, you will skip any code which is written below this line, below this line, inside the for loop.', 'start': 1104.44, 'duration': 7.666}, {'end': 1115.268, 'text': 'So if you have something outside the for loop, you will still do it.', 'start': 1112.486, 'duration': 2.782}, {'end': 1117.37, 'text': "So now let's run this.", 'start': 1115.949, 'duration': 1.421}, {'end': 1127.959, 'text': 'Awesome So you see the square of one is one, square of three is nine, and square of five is 25, but we skipped two and four.', 'start': 1119.091, 'duration': 8.868}], 'summary': "Using 'continue' statement in a for loop skips specific iterations, resulting in skipped iterations in the output.", 'duration': 36.288, 'max_score': 1091.671, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY1091671.jpg'}, {'end': 1206.493, 'src': 'heatmap', 'start': 1128.976, 'weight': 3, 'content': [{'end': 1131.718, 'text': 'Okay, now the last thing I want to cover is while statement.', 'start': 1128.976, 'duration': 2.742}, {'end': 1139.542, 'text': 'So while statement is similar to for loop with a little bit difference in the syntax.', 'start': 1131.978, 'duration': 7.564}, {'end': 1143.264, 'text': "So let's say you want to print number one to five.", 'start': 1140.123, 'duration': 3.141}, {'end': 1159.158, 'text': 'How do you do that using while loop? So in while you will say while and then the condition print i and i equal to i plus one.', 'start': 1143.825, 'duration': 15.333}, {'end': 1168.509, 'text': 'So while loop takes only one condition and until that condition is satisfied to be true, it will just keep on iterating.', 'start': 1160.259, 'duration': 8.25}, {'end': 1173.935, 'text': 'So if you run it, you will be saying one, two, three, four, five.', 'start': 1169.31, 'duration': 4.625}, {'end': 1179.121, 'text': "Okay, now be careful whenever you're doing while loop, you have to increment this counter.", 'start': 1174.596, 'duration': 4.525}, {'end': 1184.007, 'text': "If you don't increment this, then it will just go into infinite loop.", 'start': 1179.962, 'duration': 4.045}, {'end': 1188.233, 'text': 'So what happens is the way this works is let me debug it.', 'start': 1184.248, 'duration': 3.985}, {'end': 1195.93, 'text': "So here again, I'm using F8 to go to next line.", 'start': 1192.509, 'duration': 3.421}, {'end': 1206.493, 'text': 'So your I was one, as you see here, I was one and you printed I first, and then your I is two, then your I is three.', 'start': 1196.39, 'duration': 10.103}], 'summary': "Explains while loop's syntax and demonstrates printing 1-5 using it, emphasizing the need to increment the counter to avoid an infinite loop.", 'duration': 66.37, 'max_score': 1128.976, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY1128976.jpg'}], 'start': 976.201, 'title': 'Python loops', 'summary': "Explores the usage of 'continue' statement in for loops to skip specific items in python, along with the demonstration of for and while loops iterating through sequences and avoiding infinite loops, resulting in the printing of numbers 1 to 5.", 'chapters': [{'end': 1112.106, 'start': 976.201, 'title': "Using 'continue' in python for loops", 'summary': "Explains the usage of 'continue' statement in a for loop in python, demonstrating how to skip specific items in a list and execute the remaining operation, with an example of skipping even numbers while printing the square of all numbers between 1 to 5.", 'duration': 135.905, 'highlights': ["The 'continue' statement in a Python for loop allows skipping specific items in a list while executing the remaining operation, optimizing CPU cycles usage.", "Demonstrates the use of 'continue' statement to skip even numbers while printing the square of all numbers between 1 to 5 in Python, optimizing the loop operation.", "Explains the condition for skipping even numbers using 'i % 2 == 0', with a clear explanation of how the 'continue' statement works in the for loop."]}, {'end': 1240.131, 'start': 1112.486, 'title': 'For and while loops in python', 'summary': 'Covers the use of for and while loops in python, demonstrating how to iterate through a sequence and avoid infinite loops, resulting in the printing of numbers 1 to 5.', 'duration': 127.645, 'highlights': ['The while statement in Python is similar to a for loop but with a different syntax, allowing for iteration based on a single condition, as demonstrated by printing numbers 1 to 5.', 'The importance of incrementing the counter in a while loop is emphasized to avoid infinite loops, with a detailed debugging walkthrough provided to showcase the process of iteration and condition evaluation.']}], 'duration': 263.93, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/3ykIpmAxdoY/pics/3ykIpmAxdoY976201.jpg', 'highlights': ["The 'continue' statement in a Python for loop allows skipping specific items in a list while executing the remaining operation, optimizing CPU cycles usage.", "Demonstrates the use of 'continue' statement to skip even numbers while printing the square of all numbers between 1 to 5 in Python, optimizing the loop operation.", "Explains the condition for skipping even numbers using 'i % 2 == 0', with a clear explanation of how the 'continue' statement works in the for loop.", 'The while statement in Python is similar to a for loop but with a different syntax, allowing for iteration based on a single condition, as demonstrated by printing numbers 1 to 5.', 'The importance of incrementing the counter in a while loop is emphasized to avoid infinite loops, with a detailed debugging walkthrough provided to showcase the process of iteration and condition evaluation.']}], 'highlights': ["Using 'break' to terminate a loop when a specific condition is met, useful for real-time programming with lists containing less than 10,000 items.", "The 'continue' statement in a Python for loop allows skipping specific items in a list while executing the remaining operation, optimizing CPU cycles usage.", 'The range function in Python is used to specify a range of numbers using start and end indexes, allowing for efficient iteration over the specified range.', 'The examples demonstrate the practical application of for loop in tracking and totaling monthly expenses.', 'The traditional method results in a total expense of 13,020 from January to May.']}