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);
It is not a error. Compiler just suggests that you made a mistake, because there is no sense in empty condition.
An empty statement is used when you no need to perform an operation where a statement is required. It simply transfers control to the end point of the statement. It is also very useful with a while loop with the blank body and label statements.
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) { }
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With