LOOP Statements in Python
Welcome to the Digital Regenesys course in
3
Regenesys Graduate attributes
REGENESYS’ Integrated
Leadership and
Management model
Holistic focus on the individual (SQ, EQ, IQ,
and PQ)
Interrelationships are dynamic between
individual, team, institution and the external
environment (systemic)
Strategy affects individual, team,
organisational, and environmental
performance
Delivery requires alignment of strategy,
structure, systems and culture
4
Know Your Facilitator
• Maliha Khakhu
• Professional Title: AI Trainer | Data Science | Technical Mentor
• Experience: 6+ years in technical training and software development
• Expertise: Python, Data Science, ML, SQL, Power BI, Web Technologies (HTML, CSS,
JavaScript), Java, C, C++, Tableau
• Industries Worked With: Ed-Tech and IT - Corporate Training Sectors.
• Goal: Helping professionals and students bridge the gap between theory and real-world
applications
Ground Rules
4
Active
Participation
Raise hand to ask a question
One conversation at a
time
Share constructive
feedback
Respect each one’s
opinion
Avoid unwanted noise /
disturbance
Make best use of chat box or
emojis
Agenda
Understanding for and while loops
Learn Usage of break, continue and pass
Nested loops
Hands On Practice
When Do We Use
Loops?
Loops help us repeat tasks efficiently,
reducing manual effort and code redundancy.
Example:
If it rains, take an umbrella; else, wear
sunglasses.
Python Loop Statement Syntax
• 1. for - Iterate over lists, strings.
• 2. while – continues to execute the block until the condition goes
false.
While Loop
• Repeats a block of code as long as a condition is true.
• Used when number of iterations is unknown.
• Needs a loop control variable to change and avoid
infinite loop.
• Can be interrupted with break.
• Example Use Cases
• Taking input until a correct value is entered.
• Running a game loop until the user quits.
For Loop
• Iterates over a sequence (e.g., list, string,
range).
• Used when number of iterations is known
or fixed.
• More readable and compact than while for
definite loops.
• Often used with range(), enumerate(), zip().
• Example Use Cases:
• Looping through list items.
• Running a loop n times.
Break, Continue, Pass
Statement Use
break Exit loop prematurely
continue Skip current iteration
pass Placeholder – do nothing
Break – Immediately exits the current loop.
Output
Continue - Skips the current iteration and goes to the next one.
Output
Pass - Does nothing; placeholder for future code.
• Output
Practice Programs
• Sum of numbers from 1 to N
• Count vowels in a string
• Find even/odd numbers from list
• Factorial using while loop
• Find max/min from a list using loop
• Reverse a string using loop
python programming basics - loops and program

python programming basics - loops and program

  • 2.
    LOOP Statements inPython Welcome to the Digital Regenesys course in
  • 3.
  • 4.
    REGENESYS’ Integrated Leadership and Managementmodel Holistic focus on the individual (SQ, EQ, IQ, and PQ) Interrelationships are dynamic between individual, team, institution and the external environment (systemic) Strategy affects individual, team, organisational, and environmental performance Delivery requires alignment of strategy, structure, systems and culture 4
  • 5.
    Know Your Facilitator •Maliha Khakhu • Professional Title: AI Trainer | Data Science | Technical Mentor • Experience: 6+ years in technical training and software development • Expertise: Python, Data Science, ML, SQL, Power BI, Web Technologies (HTML, CSS, JavaScript), Java, C, C++, Tableau • Industries Worked With: Ed-Tech and IT - Corporate Training Sectors. • Goal: Helping professionals and students bridge the gap between theory and real-world applications
  • 6.
    Ground Rules 4 Active Participation Raise handto ask a question One conversation at a time Share constructive feedback Respect each one’s opinion Avoid unwanted noise / disturbance Make best use of chat box or emojis
  • 7.
    Agenda Understanding for andwhile loops Learn Usage of break, continue and pass Nested loops Hands On Practice
  • 8.
    When Do WeUse Loops? Loops help us repeat tasks efficiently, reducing manual effort and code redundancy. Example: If it rains, take an umbrella; else, wear sunglasses.
  • 9.
    Python Loop StatementSyntax • 1. for - Iterate over lists, strings. • 2. while – continues to execute the block until the condition goes false.
  • 10.
    While Loop • Repeatsa block of code as long as a condition is true. • Used when number of iterations is unknown. • Needs a loop control variable to change and avoid infinite loop. • Can be interrupted with break. • Example Use Cases • Taking input until a correct value is entered. • Running a game loop until the user quits. For Loop • Iterates over a sequence (e.g., list, string, range). • Used when number of iterations is known or fixed. • More readable and compact than while for definite loops. • Often used with range(), enumerate(), zip(). • Example Use Cases: • Looping through list items. • Running a loop n times.
  • 11.
    Break, Continue, Pass StatementUse break Exit loop prematurely continue Skip current iteration pass Placeholder – do nothing
  • 12.
    Break – Immediatelyexits the current loop. Output
  • 13.
    Continue - Skipsthe current iteration and goes to the next one. Output
  • 14.
    Pass - Doesnothing; placeholder for future code. • Output
  • 15.
    Practice Programs • Sumof numbers from 1 to N • Count vowels in a string • Find even/odd numbers from list • Factorial using while loop • Find max/min from a list using loop • Reverse a string using loop