Iterating through arrays using loops in C#
Using a Foreach loop with Arrays
Searching through Arrays using Loops
Using For loops with Arrays
Using For loops with Arrays
In this example we use both an Array and a for loop to print out the numbers within the array to console. The only thing we change from normal is the condition and the output. The condition is changed to the length of the array and the output is the array with its current iterated position.
Using a Foreach loop with Arrays
A foreach loop simplifies the loops of arrays by saying iterate the amount of numbers in the numbers array output the number within the array.
Searching through Arrays using Loops
In the example on the right we can see the array as normal, with additional variables shown, target which is 30 and the bool called found that is false. The loop iterates through the array as normal but nests an if statement inside to find 30 in the array, when 30 is found it outputs the answer to the console.
Iterating through arrays using loops in C#
Adam Wingell
Created on February 17, 2025
Start designing with a free template
Discover more than 1500 professional designs like these:
View
Timeline Diagram
View
Timeline Diagram 3
View
Timeline Diagram 4
View
Timeline Diagram 2
View
Triangle Diagram 3
View
Color Shapes SWOT
View
Lean Business Canvas
Explore all templates
Transcript
Iterating through arrays using loops in C#
Using a Foreach loop with Arrays
Searching through Arrays using Loops
Using For loops with Arrays
Using For loops with Arrays
In this example we use both an Array and a for loop to print out the numbers within the array to console. The only thing we change from normal is the condition and the output. The condition is changed to the length of the array and the output is the array with its current iterated position.
Using a Foreach loop with Arrays
A foreach loop simplifies the loops of arrays by saying iterate the amount of numbers in the numbers array output the number within the array.
Searching through Arrays using Loops
In the example on the right we can see the array as normal, with additional variables shown, target which is 30 and the bool called found that is false. The loop iterates through the array as normal but nests an if statement inside to find 30 in the array, when 30 is found it outputs the answer to the console.