Day 2 / 100 to Becoming a Data Science Expert
Python Control Flow and Loops
When embarking on a challenge like this, it’s good to have an efficient time management method, such as a schedule.
There are many ways to create one that works for you. It could be on Notion, Google Calendar, or a simple to-do list with allocated time sections for each activity.
This will be of great help to you, especially on days filled with tasks.
So, if you don't have one, you are encouraged to make one.
Today’s challenge is control flow and loops in Python programming.
Before I start, Python is the major programming language for data science, artificial intelligence, and machine learning.
So if you are undergoing a similar challenge to mine, it will be very good for you to get Python learning resources. It could be a Udemy course, Code Academy class, or a YouTube channel.
If you are a complete newbie to programming, you could start your skill acquisition from Python, and once you’ve perfected one programming language, learning a new one would be easier.
Back to today’s topic: control flows and loops in Python.
The flow control of a program determines the flow of execution of a program.
There are six major control structures in Python which are:
- if-else
- nested if else
- for
- while
- break
- continue
- if-else and nested if-else are decisions.
- for and while are loops.
- break ends a loop, and continue skips an iteration in a loop.
So basically, you think of your program as a line. When there is an if-else, the line breaks into two paths and has to choose one based on if a condition has been met or not.
A nested if-else statement is just an if-else statement inside an if-else statement, possibly inside an if-else statement.
For a single path to be executed in a nested if-else statement, multiple conditions have to be met.
A for loop turns that straight line into a circle that repeats itself a specified number of times or till a certain condition has been met.
A while loop repeats unless the condition has been met.
Break breaks that circle which is loop and continues the execution. Continue skips over an iteration of a loop.
That’s all for today, guys! Remember to persevere and remain focused ;)