-
Notifications
You must be signed in to change notification settings - Fork 3
Decision Making & Loops
Whenever we want to enable decision making in our program and need to run a part of code on conditional basis, we use if-elif-else constructs.
if this happens,then do this. if this doesn't happen, don't do this. if all the conditions fail , just do this. Such decisions what we make in our daily life can be simulated in programs.
-> Now, if if-condition is true, then statements inside it are executed and exited from the if-elif-else block.
-> if not, then it will check if elif-condition true, then statements inside it are executed and program will exit from the block.
-> if all above conditions are false, else block will execute and program will exit from the block.
If we want to perform some sequence of steps multiple times, we can't just copy and paste those lines of code again and again to have them executed N no.of times.
Here comes this topic, Loops. Loops as name says it runs in a circle i.e checks condition and then run the code and again checks condition and then runs the code and so forth number of times you want a particular code to run. The condition in the loops need to be false to exit out of the loops and run further line of code ahead.
There are 2 ways in python you can use looping: 1.) while loops 2.)for loops
While Loop
For loop
NOTE: Decision Making (i.e. if else ) and loops are the major building blocks of your program. Do practice a lot of questions before moving ahead.
Keep Learning. Never Settle! 😊
- Home
- 1.Introduction To Python
- 2. DataTypes
- 3. Strings and Slicing of collection
- 4.If else & Loops
- 5. Break, continue, pass
- 6. Functions
- 7. Modules
- 8. Clarifying basics
- 9. File Handling
- 10. Exception Handling
- 11. Dig into Collections
- 12. Iterators, Generators and list comprehension
- 13. lambdas , map, filter and other concepts
- 14. args, kwargs an default parameters
- 15. Functional Programming
- 16. OOPs