Code Explanation:
๐น 1. Loop Initialization
for i in range(3):
Starts a for loop
range(3) generates values: 0, 1, 2
Variable i will take these values one by one
๐น 2. Printing the Value
print(i)
Prints the current value of i
In first iteration → prints 0
๐น 3. Break Statement
break
Immediately stops the loop
Loop exits after first iteration
Remaining values (1 and 2) are not executed
๐น 4. Else Block of Loop
else:
Executes only if loop ends without break
Acts like "loop completed successfully" block
๐น 5. Else Output
print("Done")
Would print "Done"
But does NOT run because break stops the loop
๐น 6. Final Output
0

0 Comments:
Post a Comment