Reputation: 24073
I see some code of some guy that goes like this:
while (!(baseType == typeof(Object)))
{
....
baseType = baseType.BaseType;
if (baseType != null)
continue;
break;
} while (baseType != typeof(Object));
What is while(...) {...} while(...)
statement?
is the following equivalent code?
while (baseType != null && baseType != typeof(Object))
{
....
baseType = baseType.BaseType;
}
Upvotes: 8
Views: 233
Reputation: 700342
There is no while() ... while();
statement, so it's really two while statements, like:
When they have the same condition, like in your example, the second one is useless.
Actually, doing some testing I came to realise that it's actually two loops, like:
while(...) { ... }
while(...);
Upvotes: 7
Reputation: 9129
You have two while statements in a row. The 2nd could end up as an endless loop, because the first runs until the first condition is true or baseType becomes null. Then the 2nd loop starts:
while (baseType != typeof(Object));
If baseType is not changed by another thread, the loop won't terminate. Because the first loop checks the same condition, the 2nd is never run, except when baseType is null.
Your code is not exactly the same, because the first code breaks the loop if baseType is null and then ends in the endless loop. I would prefer your code, it's a lot clearer. Try to avoid continue and break.
Upvotes: 4