Perfect Example Of While And Do-While Loop In C#.Net ?
Answer / Surender Singh Negi
A perfect example of a while loop in C#.NET is when you want to count numbers from 1 to 10:
```csharp
int i = 1;
while (i <= 10)
{
Console.WriteLine(i);
i++;
}
```
An example of a do-while loop is when you want to keep asking the user for input until they enter a valid number:
```csharp
int num;
do
{
Console.Write("Enter a number: ");
if (int.TryParse(Console.ReadLine(), out num))
{
// Valid number entered, break the loop
break;
}
else
{
// Invalid input, inform user and continue the loop
Console.WriteLine("Invalid input. Please enter a valid number.");
}
} while (true);
```
| Is This Answer Correct ? | 0 Yes | 0 No |
Define satellite assembly in c#?
Can we have static indexer in c#?
What is xaml file in c#?
What is this keyword in C#?
In .NET how can you solve the DLL Hell problem?
Why do we use anonymous method in c#?
What are scriptable objects?
What is array class in c#?
What is before string in c#?
Explain boxing and unboxing in c#?
Give examples for value types?
Explain the importance and use of each, version, culture and publickeytoken for an assembly.
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)