Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TOPIC: LOOPS
- OBJECTIVES
- Be able to define loops
- Be able to understand the uses of loops
- Be able to implement loops
- Using Python
- DEFINITION:
- Basically, loops or looping in programming is a way of facilitating the repetition of an action finitely or infinitely based on a certain condition[s] without rewriting the code that implements the action.
- APPLICATION OF LOOPS(considering the learner has knowledge of data structures):
- -Printing items in a list/array, dictionary or set.
- -Adding numbers in a range
- *Basically, anything that needs to be done repeatedly
- LOOPS IN PYTHON:
- -For loop
- -While loop
- Examples/Implementation of loops:
- >>names = ['John', 'Mary', 'Jane']
- >>for name in names:
- >> print(name)
- OUTPUT
- John
- Mary
- Jane
- >>count = 0
- >>while (count < 3):
- >> print('The count is:', count)
- >> count = count + 1
- >>print "THE END!"
- OUTPUT:
- The count is: 0
- The count is: 1
- The count is: 2
- The count is: 3
- THE END!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement