Quadrition Quadrition - 1 month ago 6
C# Question

While doesn't approve true requirement

Variable i will be 0 in the end. Am I having serious problem in visual studio or in my brain?

double value = 0.0001;

int i = 0;

while(value < 0)
{
value *= 10;
i++;
}

Console.WriteLine(i);
Console.ReadLine();

Answer

The code inside the while block never runs because your while condition is actually false.

Your condition: 0.0001 < 0

This is a false statement so the while block is skipped.

Comments