Looping techniques in C#

王林
Release: 2023-09-23 15:41:06
forward
675 people have browsed it

C# 中的循环技术

Loop statements allow us to execute a statement or a group of statements multiple times. The following are the loops supported by C#-

##Sr.No.Loop types and description123do...while loopIt is similar to the while statement, only But it tests the condition at the end of the loop body

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.

Using C#, you can also use a foreach loop as shown below -

Example

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);
   }
}
Copy after login

The above is the detailed content of Looping techniques in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template