Step 2

Understanding Conditions


Now before we move on to the rest of the code, we need to go over a new topic, conditions.

A condition is something that is either True or False. For example, 10 > 20 is False while 21 > 20 is True.

With loops, conditions are what make the loop stop. As long as the condition is True, the loop will continue. If the condition becomes False, the loop will stop the next time it tries to repeat.

Add the shown code into your project. In this example, our condition is “count > 0”. (The condition will always be the one in the “()” and it is always after the while keyword)

Run the code to see what it does, it should eventually say “Auto Tunneler Complete”. It will also show the numbers 499-0 in the Terminal. Why is this? Why isn’t it 500-1?

Conditions are very powerful. All we need to is add a 0 to 500, and instead of 500 times, the loop will run 5000 times! Remember, with great power comes great responsibility, big numbers can easily make things get out of hand very quickly, be careful!