Posts

Showing posts from September, 2018

Nested Loops: Behind the Scenes!

Image
👋 Welcome! Hi! Welcome to this tutorial on  Nested Loops  where we will cover the basic principles with examples,  let’s begin!  👍 👀 First Example This is the basic structure of nested for loops. We have a for loop within another for loop. Let’s see an example in action! 📣 Note:  Please note that you should use different variables for each loop, since you might need to use these values in your code and if you use the same variable, the value can change and result in unexpected behaviors. 🔍 Step by Step! Now we have a real example of nested for loops. We have some code on the outer loop, then the inner loop and more code on the outer loop. Let’s walk through this code step by step. You can check the code and table below for a visual reference of the process. The outer loop  for i in range(3)  will start with an initial value of  0  for  i . The  print  statement will be executed. NOW.. You will...

'Break' Statement: Behind the Scenes!

Image
👋   Welcome! You will use  break  during the course and in your future projects. It's very important that you understand how it works and when to use it. 💻 Let’s begin!  👍 As you can see by the  (very subtle hahaha 😁)  graphics below, the  break  statement is the code equivalent of a  “STOP”  signal. 🔧  Use With the  break  keyword you can stop the execution of  while  loops and  for  loops. If you have nested loops, you will stop the nearest enclosing loop. (You will see examples in this tutorial ✨). ✅  Break Statement and While Loops! Let’s see a  break  statement inside a  while  loop and analyze the code in the  image below : Using  while True  means that you will enter an infinite loop if there is nothing stopping the loop because the condition will always evaluate to  True . Then, we check the if statement con...