Why is the following function an infinite loop even though Value is sometimes odd within the loop? void CountUntilOdd() { double Value = 0; while(IsEven(Value)) { Console.Write(“x= “+Value); Value = Value + 1.0; Console.WriteLine(“ and then “ + Value); Value = Value + 1.0; } }
Why is the following function an infinite loop even though Value is sometimes odd within the loop?
void CountUntilOdd()
{
double Value = 0;
while(IsEven(Value))
{
Console.Write(“x= “+Value);
Value = Value + 1.0;
Console.WriteLine(“ and then “ + Value);
Value = Value + 1.0;
}
}
The condition of a loop is checked after executing all the instructions written inside the loop.
For eg. In the given loop-
while(condition){
statement 1;
statement 2;
}
If one gets inside the loop then both statement 1 & statement 2 will be executed before again iterating through the loop.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images