Pseudocode Examples

for Loop Pseudocode Examples2 min read

What is a Pseudocode

Pseudocode is a kind of structured english for describing algorithms. It allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax. But in this post we will use the C style syntax  when write write for loop pseudocode examples.

 

The For Loop

Loops can execute a block of code a number of times.  A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.

On most programming languages(especially C based) uses the “for loop” statement as following:




The statement1 step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.

Next, the statement2 is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the ‘for’ loop.

After the body of the ‘for’ loop executes, the flow of control jumps back up to the statement3. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.

 

 

Pseudocode Example 1: Print Numbers from 1 to 100. (Pseudocode For Loop Example)

 

Pseudocode Example 2: Find Sum of Natural Numbers (1 to 100). (Pseudocode For Loop Example)

 

Pseudocode Example 3: Read 50 numbers and find their sum and average. (Pseudocode For Loop Example)

 

Pseudocode Example 4: Read 10 numbers and find sum of even numbers. (Pseudocode For Loop Example)

 

Pseudocode Example 14: Find the sum of all elements of array. (Pseudocode For Loop Example)

 

Sources:

https://www.csharp-console-examples.com/general/pseudocode-examples/

https://www.w3schools.com/js/js_loop_for.asp

http://code.wikia.com/wiki/For_loop

http://syque.com/cstyle/ch4.5.htm

Leave a Comment