Reputation: 67
I am new to programming and I have come across an issue called a "Possible mistaken empty statement" now I have done a lot of research on this topic, and the solution I was given was to remove the semi colon after the if statement, however this only produces more warnings and more errors that I currently do not know the solution to, I would very much appreciate the help, the language I am using is C#.
if (checkBox5.Checked = true) ;
Double value5 = Convert.ToDouble(checkBox4.Checked);
value5 = +1;
Double result5 = value5;
label2.Text = Convert.ToString(result5);
Upvotes: 5
Views: 25241
Reputation: 10452
The problem is the semi-colon at the end of your if as well as the single '=', should be:
if (checkBox5.Checked = true) ;
Should be:
if (checkBox5.Checked == true) // double '==' for equality comparison
Upvotes: 1
Reputation: 5433
In addition to @des and @Soner answers, why don't you just do this :
if (checkBox5.Checked)
label2.Text = Convert.ToDouble(checkBox5.Checked).ToString();
I'm assuming you don't intend to increment value5
by 1
as it should be value5 += 1;
Upvotes: 0
Reputation: 98830
You should use;
if (checkBox5.Checked == true)
not
if (checkBox5.Checked = true)
=
is assignment operator, ==
is equality operator.
Check out;
And or course when you check your true value, you can use your if condition like;
if (checkBox5.Checked)
{
// Do something if checkBox5 is checked.
}
And if you use semicolon after your if condition;
if (checkBox5.Checked = true) ;
is equivalent to
if (checkBox5.Checked = true) { }
So in your case I think you shouldn't use semicolon either. Because if you use it, your code will be look like;
if (checkBox5.Checked = true)
{
}
Double value5 = Convert.ToDouble(checkBox4.Checked);
value5 = +1;
Double result5 = value5;
label2.Text = Convert.ToString(result5);
which I assume you don't want to do this. And remember, even if there is no body to execute, doesn't mean that the loop terminates.
Upvotes: 4
Reputation: 27614
I guess that this is what you want:
if (checkBox5.Checked == true)
{
double value5 = Convert.ToDouble(checkBox4.Checked) + 1;
label2.Text = value5.ToString();
}
=
is assigment, whereas ==
is checking for equality, on the other hand semicolon after if
will terminate whole if
statement.
Note that when you are checking for true
then you can use this:
if (checkBox5.Checked) { }
Upvotes: 9
Reputation: 33381
if (checkBox5.Checked == true) ; // or you can use if (checkBox5.Checked)
// ^------------------- `=` assignment operator must be `==` equals
{ // missed
Double value5 = Convert.ToDouble(checkBox4.Checked);
value5 = +1;
// ^_______________ I assume you need `=+` addition assignment operator instead
// assigning `+1` to `value5 `
Double result5 = value5;
label2.Text = Convert.ToString(result5);
} /// missed
Upvotes: 0