Loop: for & range

for loop : it is used to iterate over a sequence (like a list, tuple, string, or range). The loop executes a block of code once for each item in the sequence. Normally range function is used with for.



The range() Function

The range() function is used to generate a sequence of numbers. It's commonly used in loops, especially for loops, to iterate over a sequence of numbers. The function supports three main parameters: start, stop, and step. Here's a breakdown:

SYNTAX: range(start, stop, step)

Example: in code bellow we print X for i starting from Start value 0 and ending to 9 (Stop value -1)








range with steps

Example: in code bellow we print X for i starting from Start value 0 and ending to 9 (Stop value -1) but in step of 2.










Comments

Popular posts from this blog

Computer Programming Brief History.

How to install Deepseek R1 local machine.