Programming Code Examples

For i in Range Pseudocode2 min read

“For i in range” is a type of loop statement in Python that allows you to iterate over a sequence of numbers. Here is an example of pseudocode for a “for i in range” loop:

In this example, “start” is the starting value of the loop, “end” is the ending value of the loop, and “step” is the increment value (default is 1). The loop will iterate from the “start” value to the “end” value, incrementing by the “step” value each time. For example, if start is 0, end is 5, and step is 1, the loop will iterate over the values 0, 1, 2, 3, 4, 5.




Here are some examples of “for i in range” loop in pseudocode:

Print the numbers 0 to 9:

Print the even numbers from 0 to 10:

Sum the numbers from 1 to 100:

Multiply all the elements in an array:

Print the characters in a string:

Iterate through a dictionary and print its keys and values:

Note that these examples are in pseudocode and may not run correctly in a real programming language. The syntax may vary depending on the programming language you are using.

Here’s an example of a “for i in range” loop in Python:

Here’s an example of a “for i in range” loop in Python:

In this example, the loop starts at 0 (the default start value) and ends at 9 (the default end value is exclusive), incrementing by 1 (the default step value) each time. The output will be:

Another example :

In this example, the loop starts at 0, ends at 11 and step is 2. The output will be:

You can also use variable to define your range:

In this example, the loop starts at 2, ends at 7 and step is 1. The output will be:

Add comment