For Loop
Python for loop is similar to while loop, but it makes more easy to iterate from a sequence like list, tuple, dictionary, set or string.
Break Statement
The break statement is used to break or stop the loop, even if the condition is true.
Pass Statement
The pass statement is used to avoid the error even if the loop is empty. It doesn't break the loop and instructs to do nothing.
Continue Statement
The continue statement is used to skip the current iteration and continue with the next one.
Else Statement
when the condition is no longer true, then you can execute a code using else statement.
Range() Function
Python range() function is used to set the number of times a loop is iterate. It generate a sequence of numbers, that can be specify by the starting from (0 by default), stop at less than 1 by the specified number and increments by (1 by default). shown below,
- changes the default starting.
- change the default increment.
Nested Loop
Writing a loop inside a another loop is called nested loop.
Try to create a nested loop using while loop.
Comments
Post a Comment