Python 3.4 - Control Structures

There are three types of control structures:

1. Sequential Control
2. Conditional Control
3. Iterative Control

1. Sequential will follow in order the code written from top to bottom.
2. Conditional will choose which condition is true and execute that code.
3. Iterative will choose which condition is true and execute that code, it will check again to see if the condition is true and continue to execute that code, ad nausea. Once the condition is false it will execute that code.

Sequential is easy enough. Conditional usually requires some sort of input or data to work through. For example:

var = (int(integer("enter a number:"))

if var < 10:
print('you are less than 10')
if var > 10:
print('you are greater than 10')
else:
print('you are 10!')

Again, it will choose which statement is true, based on the conditions created and work through that code, ignoring the other code.

Iterative uses the while statement that will check if a condition is true and while it is true will execute that code. Once it is not true it will exit the code and execute any other code if there is any. For example:

var = 0

while var < 10:
print('you are less than 10')
var = var + 1

print('done')

It won't print done until the condition is no longer true.

https://www.youtube.com/watch?v=kIPpTYjareA

Comments

Popular posts from this blog

Pyhton 3.4 - Continue

Conversations Ongoing: Valuing Modernization in Early European History

Conversations Ongoing: A Bunch of Amateurs