From a90c81cd529df34dcd6552236ef84e47d70e0280 Mon Sep 17 00:00:00 2001 From: DorRon Date: Sat, 2 Aug 2014 21:03:55 -0400 Subject: [PATCH] Create loops Added Python loops. --- python/loops | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 python/loops diff --git a/python/loops b/python/loops new file mode 100644 index 0000000..e610bbd --- /dev/null +++ b/python/loops @@ -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.