dimanche 24 février 2019

When I use 'While' in C#, I don't wanna print the last calculation

Hi I have a question about using 'while' in C#.

I made a loop using 'while', but I don't know how to make did not print the last calculation.

Here is my code.

if (obj.ControlCommand == 2)
{
    try
    {
        while (obj.LiftHeight > sendMessage.LiftHeight)
        {
             sendMessage.LiftStatus = 12;
             sendMessage.LiftHeight += 0.1f;
             Thread.Sleep(1000);

             if (sendMessage.LiftHeight >= obj.LiftHeight)
             {
                 sendMessage.LiftStatus = 0;
                 sendMessage.LiftHeight = obj.LiftHeight;
             }
        }

When I set obj.LiftHeight to 2.95 for instance, it will increase 0.1 per 1sec.

But sendMessage.LiftHeight shown '... , 2.8, 2.9, 3.0, 2.95, 2.95 ... '

I want to make ' ..., 2.8, 2.9, 2.95, 2.95 ... '

What should I change to make like that?

        while (obj.LiftHeight < sendMessage.LiftHeight)
        {
             sendMessage.LiftStatus = 12;
             sendMessage.LiftHeight -= 0.1f;
             Thread.Sleep(1000);

             if (sendMessage.LiftHeight <= obj.LiftHeight)
             {
                 sendMessage.LiftStatus = 0;
                 sendMessage.LiftHeight = obj.LiftHeight;
             }
        }

Aucun commentaire:

Enregistrer un commentaire