What you’re doing in the below code is:
- making an int (paashaas), setting it to 0,
- then making another int (p), setting the value of the second int (p) also to 0,
-
then keep checking the second int (p) in the while loop, while changing the first int (paashaas) every time. Because of this, you will get stuck in the while loop. The value of p doesn’t get changed, only the value of paashaas.
private void textBox1_TextChanged(object sender, EventArgs e) { int paashaas = 0; int p = paashaas; while (p <= 4) { MessageBox.Show("The value of i is : " + paashaas); paashaas = paashaas + 1; } }
Also, i would use a for loop if i were you, if you want to do a certain action x times. For example take this code:
for(int i=1; i<=4; i++)
{
MessageBox.Show("The value of i is: " + i);
}
This code will show 4 message boxes, with the text:
- The value of i is: 1
- The value of i is: 2
- The value of i is: 3
- The value of i is: 4
I think the working code that you’re looking for is:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(textBox1.Text == "easter bunny")
{
for(int i=0; i<10; i++)
{
MessageBox.Show($"You entered easter bunny in the textbox! {i}");
}
}
}
1
solved if i type Easter Bunny in textbox1 it needs to be shown 10x on label1. i need to use the While Statement