Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a scenario where I want to check the value of a cell in an application. When the value of the cell hits 0 or -1 I'd like the test to continue. So I have:

while (!cell.Value.Equals("0") || !cell.Value.Equals("-1")) 
{
    Console.WriteLine("Value ({1})",cell_value.Value);
    Thread.Sleep(15000);
}

Unfortunately, when the cell reaches 0, it doesn't appear to 'break' out of the loop.

Output:
    Value (20)
    Value (13)
    Value (10)
    Value (9)
    Value (4)
    Value (1)
    Value (0)
    Value (0)
    Value (0)
    Value (0)

Is it best to try this with a while / do + while loop or is a for loop better?

Thanks,

J.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
139 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your condition should probably be:

while (!cell.Value.Equals("0") && !cell.Value.Equals("-1"))

As it is currently written, at least one of the sides will be true (any string is always either NOT "0" OR NOT "-1").


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...