Make a loop for 2 labels when clicking

1

I need a loop for 2 labels where each one appears text already specified in the code. Just out of curiosity. I wanted a loop with the same effect as the code below:

private void button1_Click(object sender, EventArgs e)
{
     lbl_1.Text = "Ziummmmmm";

     ++NumberOfClick;
     switch(NumberOfClick)
     {
          case 1:
              lbl_1.Text = "Ziummmmmm";
              break;
          case 2:
              lbl_2.Text = "Ploft";
              break;
          case 3:
              lbl_1.Text = "";
              lbl_2.Text = "";
              break;
     } 
}

I'm trying to make a loop , but it's incomplete and I do not know how to continue, any help I accept.

while (lbl_1.Text == "Ziummmmmm")
{
      lbl_2.Text = "Ploft";
      while (lbl_2.Text == "Ploft")
      {
           lbl_1.Text = "";
           lbl_2.Text = ""; 
      }              
}
    
asked by anonymous 27.06.2015 / 08:02

1 answer

0

The only reason you see the change from one text to another is that it happens under the condition that an event occurs (in this case, you click the mouse button). If you change the texts in a loop, all you will see will be the last text changed / updated (Since you had no condition to "hold" the toggle, no event, it simply updated to the end). So your reasoning does not make sense.

However, you could do this:

int i = 0;
while (i < 3)
{
    if (i == 1)
    {
        lbl_1.Text = "Ziummmmmm";  
    } 
    else if (i == 2)
    {
        lbl_2.Text = "Ploft";  
    } 
    else if (i == 3)
    {
        lbl_1.Text = "";
        lbl_2.Text = "";
    }
    i++;
}

In your first example, you update the i variable (which in this case is NumberOfClick) with each mouse click. In the way you want, the variable is updated with each iteration / loop. That is, everything you should see in the Label, finally, are just the final results, which in this case are empty Strings ("", "").

    
27.06.2015 / 08:47