python in loop programming language
java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.
TYPE OF LOOPS (Type of LOOP): - PYTHON consists mainly of three types of LOOP: -
01. for loop
02. while loop
03. Nested loops
Loop Control Statements: - Like its name, the Loop Control Statement is used to control the execution of any LOOP. For example, you suppose that you have to print numbers from 1 to 100 in the output but you want 20, 40, 60, 80 and 100 of these 100 numbers printed in the output. You can do this by using Loop Control Statements.
Type Of Loop Control Statements (Types of Loop Control Statements): - Python consists mainly of three types of Loop Control Statements.
01. break statement
02. continue statement
03. pass statement
Suppose you have to print numbers from 1 to 10 in the output. Now if you print numbers from 1 to 10 in the output one by one, then this task is very difficult. But with the help of for loop, we can do this work very easily. By looking at the example below, you can understand it very easily.
See the example below: -
Suppose we have to print numbers from 1 to 10 in the output.
Because with the help of a break statement, we can create a condition from which we can control the numbers being printed in the output.
java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.
TYPE OF LOOPS (Type of LOOP): - PYTHON consists mainly of three types of LOOP: -
01. for loop
02. while loop
03. Nested loops
Loop Control Statements: - Like its name, the Loop Control Statement is used to control the execution of any LOOP. For example, you suppose that you have to print numbers from 1 to 100 in the output but you want 20, 40, 60, 80 and 100 of these 100 numbers printed in the output. You can do this by using Loop Control Statements.
Type Of Loop Control Statements (Types of Loop Control Statements): - Python consists mainly of three types of Loop Control Statements.
01. break statement
02. continue statement
03. pass statement
SYNTAX OF FOR LOOP
Example 1:-
for c in range(1,11): print (c)
Output:-
1
2
3
4
5
6
7
8
9
10
Example 2:-
for n in 'PYTHON': print (n)
Output:-
P
Y
T
H
O
N
Example 3:-
animals = ['tiger', 'lion', 'zebra', 'elephant', 'monkey'] for name in animals: print ('animal :', name)
Output:-
animal: tiger
animal: lion
animal: zebra
animal: elephant
animal: monkey
WHILE LOOP
The syntax of while loop:-
while condition: statement(s)The statement in the while loop is executed until the condition of the while loop is fulfilled.
See the example below: -
Suppose we have to print numbers from 1 to 10 in the output.
Example 1:-
count = 1 while (count <= 10): print ('The count is:', count) count = count + 1
Output:-
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
The count is: 9
The count is: 10
BREAK STATEMENT
For example, suppose a loop is going to print the numbers from 1 to 100 in the output, but if we want to have any number from 1 to 100, like 50 or 60, But if we stop printing, we can do this with the help of a break statement.Because with the help of a break statement, we can create a condition from which we can control the numbers being printed in the output.
Example 1:-
for c in range(1,11): if c==5: break print (c)
Output:-
1
2
3
4
Example:-
shapes = ["square", "rectangle", "circle", "triangle", "oval"] for x in shapes: if x == "triangle": break print('Great shape :', x)
Output:-
Great shape: square
Great shape: rectangle
Great shape: circle
Comments
Post a Comment