Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create loops #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions python/loops
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#loops are used to repeat parts of your code.
#There are two main ways to loop in Python,
#Using a FOR loop and a WHILE loop

#a for loop is written like this
for i in range(1,10):
print i

#make sure to add a comma in between your numbers and a colon at the end of the initial line.
#the range function is exclusive therefore the output would be numbers 1 through 9 not including 10.

#a while loop is written as follows
x = 10
y = 0
while x > y:
print "while loop example"
y += 1 #this iterates variable y every time the loop is runned (same as writing y = y + 1)

#the result would be outputting "while loop example" ten times,
#until x is no longer greater than y

#be sure to familiarize yourself with the BREAK and CONTINUE statements as well,
#as they are vital for mastering python's loop control flow.