Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible mistaken empty statement

Tags:

c#

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);
like image 859
user2013481 Avatar asked Jan 26 '13 11:01

user2013481


People also ask

What does possible mistaken empty statement?

It is not a error. Compiler just suggests that you made a mistake, because there is no sense in empty condition.

What is an empty statement in C#?

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.


3 Answers

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) {  }
like image 121
Zbigniew Avatar answered Oct 30 '22 01:10

Zbigniew


You should use;

if (checkBox5.Checked == true)

not

if (checkBox5.Checked = true)

= is assignment operator, == is equality operator.

Check out;

  • http://msdn.microsoft.com/en-us/library/sbkb459w(v=vs.110).aspx
  • http://msdn.microsoft.com/en-us/library/53k8ybth(v=vs.110).aspx

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.

like image 38
Soner Gönül Avatar answered Oct 30 '22 02:10

Soner Gönül


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
like image 20
Tom Studee Avatar answered Oct 30 '22 03:10

Tom Studee