Home > Article > Backend Development > Looping techniques in C#
Loop statements allow us to execute a statement or a group of statements multiple times. The following are the loops supported by C#-
Loop types and description | |
---|---|
while loopIt repeats a statement or a set of statements when a given condition is true. It tests the condition before executing the loop body. | |
for loop p>It executes a series of statements multiple times and abbreviates management Code for loop variables. | |
do...while loopIt is similar to the while statement, only But it tests the condition at the end of the loop body |
using System; using System.Collections; class Demo { static void Main() { bool[] arr = new bool[5]; arr[0] = true; arr[1] = true; arr[2] = false; arr[3] = false; BitArray bArr = new BitArray(arr); foreach (bool b in bArr) { Console.WriteLine(b); } bool str = arr[1]; Console.WriteLine("Value of 2nd element:"+str); } }
The above is the detailed content of Looping techniques in C#. For more information, please follow other related articles on the PHP Chinese website!