Perfect Example Of While And Do-While Loop In C#.Net ?



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

Post New Answer

More C Sharp Interview Questions

Define satellite assembly in c#?

1 Answers  


Can we have static indexer in c#?

1 Answers  


What is xaml file in c#?

1 Answers  


What is this keyword in C#?

1 Answers  


In .NET how can you solve the DLL Hell problem?

1 Answers   Siebel,


Why do we use anonymous method in c#?

1 Answers  


What are scriptable objects?

1 Answers  


What is array class in c#?

1 Answers  


What is before string in c#?

1 Answers  


Explain boxing and unboxing in c#?

1 Answers  


Give examples for value types?

1 Answers  


Explain the importance and use of each, version, culture and publickeytoken for an assembly.

1 Answers  


Categories