Type of loops in C#

/
0 Comments

A loop statement allows us to execute a statement or a group of statements multiple times and following is the general from of a loop statement in most of the programming languages.

The following loop types are available to handle looping requirements.

  • While loop
  • for loop
  • do while loop
  • Foreach loop

While loop

Description :
A while loop will check a condition and then continues to execute a block of code as long as the condition evaluates to a boolean value of true.

for loop

Description :
A for loop works like a while loop, except that the syntax of the for loop includes initialization and condition modification. for loops are appropriate when you know exactly how many times you want to perform the statements within the loop.

do while loop

Description :
A do loop is similar to the while loop, except that it checks its condition at the end of the loop. This means that the do loop is guaranteed to execute at least one time.

Foreach

Description :
A foreach loop is used to iterate through the items in a list. It operates on arrays or collections such as ArrayList, which can be found in the System.Collections namespace.



You may also like

No comments:

Powered by Blogger.