myVar = 25
if myVar > 10:
    print('Above 10!')

"""
Explanation: title: "Control Flow in Python"
subtitle: "CU Psych Scientific Computing Workshop"
weight: 1104
tags: ["core", "python"]

Goals of this lesson
Students will learn:

How to use if/else and for loops in python
How to indent code correctly in python

Links to Files
The files for all tutorials can be downloaded from the Columbia Psychology Scientific Computing GitHub page using these instructions. This particular file is located here: /content/tutorials/python/1-r2python-translation/3-control-flow.ipynb.
Indenting in python

Python, unlike R, is strict about indentation! 
Indentations in python often have bearing on the order in which they are executed, and switching indentation can change how code runs (or break it)
Coming from R, indentation might seem annoying at first, but eventually this can help with code readability 
Ultimately, python is trying to help us stay organized


If statements

If statements in python are the equivalent of the following English: "If condition X is met, then do action Y"
If statements in python consist of the following syntax

if (condition X):
    actions...
End of explanation
"""


if myVar > 5:
    print('Above 10!')
    if myVar > 20:
        print('Above 20!')

"""
Explanation: Nesting If Statements
Any conditional statements within others are called 'nested'
End of explanation
"""


myVar2 = 'dog'
if myVar2 == 'cat':
    print('meow')
else:
    print('woof')

"""
Explanation: Else Statements

It is also very helpful to specify code that we want to run if a condition is NOT met
Else statements in python always follow if statements, and consist of the following syntax

if (condition X):
    actions...
 else:
    actions...
End of explanation
"""


myVar2 = 'dog'
if len(myVar2) == 3:
    print('3 letters long')
elif myVar2 == 'dog':
    print('woof')
else:
    print('unknown animal')

myVar2 = 'dog'
if len(myVar2) == 3:
    print('3 letters long')
if myVar2 == 'dog':
    print('woof')
else:
    print('unknown animal')

"""
Explanation: Else If & Sequential If Statements

We may also want to specify a series of conditions
Python always evaluates conditions on the same nest level in order, from top to bottom 
Elif means 'else if' -- only run this statement if the previous if statement condition was not met, and the condition following is met
Sequential if statements on the same level will run if the statement condition is met, regardless of the previous
End of explanation
"""


nums = [2,3,4,-1,7]
for number in nums:
    print(number)

"""
Explanation: Loops

Looping is a great way to apply the same operation to many pieces of data

Looping through a list
End of explanation
"""


for i in range(10):
    print(i)

"""
Explanation: Looping a certain number of times
End of explanation
"""


stringList = ['banana', 'mango', 'kiwi', 'blackberry']
# fancy looping with enumerate()
for index, item in enumerate(stringList):
    print(index, item)

"""
Explanation: Fancly looping with enumerate
End of explanation
"""


for i in stringList:
    for j in range(4):
        print(i, j)

"""
Explanation: Nested loops
End of explanation
"""


