#--------- # Filename: breaktest.py # Author: Dan Fleck # Date: 1/28/2008 # # CS112 - Functions that demonstrate the break statement #--------- #--------- # imported modules/libraries #--------- # None #--------- # function definitions #--------- def myFunc3(x): if x > 5: return "No good", "9" else: return "Good answer", "5" def ifTester(v1, v2): if v1 > v2 or v2 > 90: print "We got into the if" # Test Break statement 1 def breakTester(): x = 5 y = "myString" zqr = x + y #if 4 > 7: # print "We got into the if" for i in range(5): print 'i is', i if i == 3: continue print "Still in for loop" print "Done wirh for loop" # Test Break statement 2 def breakTester2(): for i in range(10): print 'i is', i for j in range(3): print ' j is ',j if i == 7: break # Else example 1 def elseExample(inStr): for i in inStr: print i if i in ['a','e','i','o','u']: print 'Found a vowel' break else: print 'There are no vowels in %s ' %(inStr) #Else example 2 def elseExample2(): for i in range(12): if i > 10: print 'i was greater than 10 in the loop' break else: print 'i was never greater than 10 in the loop!' # Find all the prime numbers between 2 and 20 def primeNumberFinder(): for n in range(2, 20): for x in range(2, n): if n % x == 0: # n % x returns the remainder of n divided by x, what does this mean? print n, 'equals', x, '*', n/x break # Why do I break here? else: # loop fell through without finding a factor print n, 'is a prime number' #--------- # main #--------- def main(): #ans = "Test" #print ans #ans, ans2 = "Good answer", "5" #myFunc3(4) #print "The answer is :"+ans+" And"+ans2 breakTester() #breakTester2() #elseExample2() #myWord = raw_input('Give me a word -->') #elseExample(myWord) #primeNumberFinder() main()