For loops in Python
“Don’t settle for average. Bring your best to the moment. Then, whether it fails or succeeds, at least you know you gave all you had.” 🙂 HAPPY DIWALI FRIENDS 🙂
A for loop in Python is a control flow statement that is used to repeatedly execute a group of statements as long as the condition is satisfied. A for loop is used for iterating over a sequence. with the for loop we can execute a list, a dictionary, a tuple , a string or a set .
USE OF FOR LOOP For loops are traditionally used when you have a block of code which you want to repeat a fixed number of times .
1) For loop
2) looping in string . It contain a sequence of characters . lopping in the word Nikita
3) break Statement . The break statement in Python terminates the current loop and resumes execution at the next statement we can stop the loop before it has looped through all the items
4)continue Statement. Continue statement is a loop control statement that forces to execute the next iteration of the loop while skipping the rest of the code inside the loop for the current iteration only .we can stop the current iteration of the loop, and continue with the next:
5)pass Statement In Python, pass is a null statement. The interpreter does not ignore a pass statement, but nothing happens and the statement results into no operation. The pass statement is useful when you don’t write the implementation of a function but you want to implement it in the future.
6) range() Function .The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.
7)Nested Loops . A nested loop is a loop inside a loop. The “inner loop” will be executed one time for each iteration of the “outer loop“.
8)Else in For Loop The else clause of a loop ( for / while ) gets executed only if the loop has completed its execution fully without hitting a break statement (in other words, loop has completed normally). The statements inside the loop’s else clause will get executed once after the loop has completed normally.
Thanks you friends 🙂 And yes don’t forgot to put doubts . we will meet in next article Till then #Happycoding #HaveFun And last but no the least Happy Diwali Guys