|
| |||||||||
| Tags: c program, foreach loop, loop, programming language, while loop |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to use Looping in C#?
Hi friends, I am new to this forum, so please ignore my mistakes. I am new to C# programming language. But I am not new to programming language since I have done C programming language. I have done looping in the C language. I know the concepts of looping, but I know that the type that used in C must be different then C#. So please anyone can tell me the correct way to use the looping in C#..?? Please help me soon..!!
__________________ (\__/) (='.'=) This is Bunny. Copy and paste bunny into your (")_(") signatureto help him gain world domination |
|
#2
| ||||
| ||||
| Re: How to use Looping in C#?
Because of the looping in any language, you get an ability to repeat a block of code for n number of times. There are four different ways of loops in C#, they are :
|
|
#3
| |||
| |||
| Re: How to use Looping in C#?
I think that the While Loop is the most simple loop in C#. The while loop simply executes a block of code as long as the condition you give it is true. Check the below example, so that you can know it very clearly : Code: using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number = 0;
while(number < 10)
{
Console.WriteLine(number);
number = number + 1;
}
Console.ReadLine();
}
}
} |
|
#4
| ||||
| ||||
| Re: How to use Looping in C#?
If you know how many times you want to run the code before executing, then you can use the For Loop. You can also use it if you have a variable containing the amount. See the example of For Loop below : Code: using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number = 10;
for(int i = 0; i < number; i++)
Console.WriteLine(i);
Console.ReadLine();
}
}
}
__________________ The FIFA Manager 2009 PC Game |
|
#5
| ||||
| ||||
| Re: How to use Looping in C#?
If you have worked on While loop in other language, the Do Loop is almost similar to that loop. The do loop evaluates the condition after the loop has executed, due to which it is assured that code block is always executed at least once.Just glance an example below : Code: do
{
Console.WriteLine(number);
number = number + 1;
} while(number < 10); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to use Looping in C#?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Output not looping in C++ | Guntoor | Software Development | 6 | 3 Weeks Ago 10:19 PM |
| Stuck with bar looping in vista 32 bit | Ajmil | Windows Software | 5 | 26-06-2011 11:01 PM |
| Continuous Looping In iPad Video | Depo | Portable Devices | 5 | 25-12-2010 10:19 PM |
| Mozilla goes looping the same Page | Zadora | Technology & Internet | 9 | 26-03-2009 11:09 AM |
| VBA: Looping Through Tasks | StGhurka | Microsoft Project | 2 | 15-01-2009 03:25 AM |