For Loop
Duration: 16 min
This video lesson is available to enrolled students.
Inside: a video lesson and guided study material.
Module outline
- TCS One Shot Free Videos & Notes: TCS Preparation
- Numerical Ability (Foundation Section): Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Algebra, Probability, Profit and Loss, Simple Interest and Compound Interest, Time and Work, Pipe and Cistern, Mensuration and Geometry, Mental Ability, Age Problems, Statistics, Arithmetic, Partnership, Speed Mathematics and Basic Mathematics
- Reasoning Ability (Foundation Section): Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Seating Arrangements, Blood Relations, Directions (Direction Test), Analytical Reasoning (Counting Figures Reasoning), Puzzle Solving (Puzzles), Calendar, Clock, Cubes & Dices, Selection Decision Table (Decision Making), Crypt Arithmetic, Venn Diagram, Data Arrangement, Inequality, Analogy, Ranking, Order and Sequence, Logical Sequence Of Words
- New Pattern-Verbal Ability (Foundation Section): Sentence Completion (Fill in the blanks), English Writing Ability
- Old Pattern-Verbal Ability (Foundation Section): Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, Tenses, Pronoun, Preposition, Articles, Direct and Indirect Speech, Conjunction, Modals, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Correction (Error Correction), Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Verbal Analogy (Word Based Analogy), Active Passive Voice (Voice), Determiner, Facts, Inference and Judgements, Adverb, Cloze Test (Cloze Passage), Sentence Construction, Verb
- Advanced Quantitative Ability: TCS NQT Advanced Quantitative Ability
- Advanced Reasoning Ability: TCS NQT Advanced Reasoning Ability
- Advanced Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Python for Placements by Yash Sir, DSA using Python, Object Oriented Programming (OOPS), Programming in C++, Java
- TCS Full Length Mock Test:
- TCS Interview & Resume Prep: MR & HR Interview Preparation, TCS Interview Preparation, Mock Interview, Interview Recordings, Resume Preparation, Resume Review
- Mega Test:
- Grand Test:
AI summary & chapters
AI Summary
An AI-generated summary of this video lecture.
This video is a Python programming tutorial focused on for loops. The instructor, Yash Jain, begins by demonstrating a basic for loop using the `range()` function to print a sequence of numbers. He then explains the syntax of the for loop, showing how to iterate over a range of values. The lesson progresses to more complex examples, including a task to find all numbers divisible by 3 from 1 to 100. The instructor shows two different approaches: one using a `for` loop with a `range(1, 101)` and an `if` statement to check divisibility, and another using a `for` loop with a `range(3, 101, 3)` to directly iterate over multiples of 3. The video uses a code editor to display the Python scripts and a terminal to show the output of the programs, providing a practical, hands-on learning experience.
Chapters
0:00 – 2:00 00:00-02:00
The video opens with a view of a Python code editor, showing a file named `10.1ForLoops.py`. The instructor, Yash Jain, introduces the topic of for loops. The code in the editor demonstrates a simple for loop: `for i in range(3): print('Attempt', i)`. The instructor explains that this loop will execute the print statement three times, with the variable `i` taking on the values 0, 1, and 2. The terminal at the bottom of the screen shows the output of the program, which is 'Attempt 0', 'Attempt 1', and 'Attempt 2'. The instructor emphasizes that the loop runs for the number of times specified in the range function.
2:00 – 5:00 02:00-05:00
The instructor continues to explain the for loop syntax, showing that the loop variable `i` is automatically incremented by 1 in each iteration. He demonstrates that the loop will run for the number of times specified in the range, which is 3 in this case. He then shows a more complex example: `for i in range(1, 4): print('Attempt', i)`. This loop starts from 1 and goes up to, but does not include, 4, so it will print 'Attempt 1', 'Attempt 2', and 'Attempt 3'. The instructor explains that the range function can take one, two, or three arguments: `range(stop)`, `range(start, stop)`, and `range(start, stop, step)`. He also shows an example with a step of 2: `for i in range(1, 10, 2): print('Attempt', i)`, which will print 'Attempt 1', 'Attempt 3', 'Attempt 5', 'Attempt 7', and 'Attempt 9'.
5:00 – 10:00 05:00-10:00
The instructor transitions to a new file, `10.2ForLoops.py`, and presents a task: to find all numbers divisible by 3 from 1 to 100 and print them. He writes a for loop: `for number in range(1, 101):`. Inside the loop, he uses an if statement to check if the number is divisible by 3: `if number % 3 == 0:`. If the condition is true, he prints the number and increments a counter variable `count`. After the loop, he prints the total count of such numbers. The instructor then runs the code, and the terminal displays all the numbers divisible by 3 from 1 to 100, followed by the message 'We have 33 numbers divisible by 3 from 1 to 100'.
10:00 – 15:00 10:00-15:00
The instructor introduces a more efficient way to solve the same problem. He opens a new file, `10.3ForLoops.py`, and writes a for loop that directly iterates over the multiples of 3: `for number in range(3, 101, 3):`. This loop starts at 3 and increments by 3 each time, so it will only execute for numbers that are divisible by 3. Inside the loop, he prints the number and increments the counter. He runs the code, and the terminal output is identical to the previous method, but the loop runs only 33 times instead of 100. The instructor explains that this is a more efficient approach because it avoids the unnecessary checks for numbers that are not divisible by 3.
15:00 – 15:44 15:00-15:44
The instructor concludes the lesson by summarizing the key points. He reiterates that the for loop is a powerful tool for iterating over a sequence of numbers. He emphasizes the importance of understanding the `range()` function and how to use it with different arguments to control the start, stop, and step of the iteration. He also highlights the difference between the two approaches to finding numbers divisible by 3: the first is more general but less efficient, while the second is more specific and efficient. The video ends with the instructor encouraging viewers to practice these concepts.
The video provides a comprehensive tutorial on Python for loops, starting with the basic syntax and progressing to practical applications. The instructor effectively uses code examples and terminal output to demonstrate how for loops work, emphasizing the importance of the `range()` function. The lesson is structured to build understanding from simple to more complex concepts, culminating in a comparison of different programming approaches to solve the same problem. This approach helps students understand not only how to write code but also how to write efficient and effective code.

