-
Notifications
You must be signed in to change notification settings - Fork 1
/
15_Conditional Statements - For Loop & While Loop.py
46 lines (22 loc) · 1.45 KB
/
15_Conditional Statements - For Loop & While Loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
1. Uses of Loops :-
a) Loop is useful in areas whereas lot of data has to be printed on the screen, manually doing this work would require alot of time and efforts.
b) Loops are also helpful in searching date from lists, dictionaries, tuples, sets.
2. Why do we use Loops ?
* Complex problems can be simplified using loops.
* Less amount of code required for our program.
* Lesser code so lesser chance or error.
* Saves a lot of time and effort.
* Can write code that is practically impossible to write.
* Searching and sorting algorithms that require too many iterations can be simplified using loops.
3. Advantages of Loops.
* The reusability of code is ensured.
* We do not have to repeat the code, again and again, we just have to write in one time.
* We can transverse through data structures like list, dictionary, tuples.
* We apply most of the findings algorithms through loops.
4. Difference between For 'Loop' & 'While' Loop.
a) A 'for' statement loop runs until the iteration through sets, lists, tuples, dictionaries etc.. or a generator function is completed.
b) A 'while' statement runs until the condition becomes false.
c) A 'for' statement is used for areas whereas we are already familiar with the number of iterations .i.e we already know how many iterations has to be done.
d) A 'while' statement is used for areas whereas the number of iterations are unknown.
'''