Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
A loop is a programming function that iterates a statement or condition based on specified boundaries.
The loop function uses almost identical logic and syntax in all programming languages. Thus, a specific statement or a group of instructions is continuously executed until a specific loop body or boundary condition is reached. The result of the entire loop body’s first operation cycle serves as the next repetition’s starting point.
A loop repeatedly executes code in its body until the loop conditional statement becomes false.
A loop is divided into two parts:
Here is an example of a loop (a for loop) in C#:
int i; string numbers = ""; for (i = 1; i <= 9; i++) numbers += i.ToString(); Console.WriteLine(numbers);
The output of the example is: "123456789."