Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If Statement Contains Only "True"

I am converting a vb6 app into c# and I've come across something I don't quite understand. I've never seen an if statement structure where the expression being evaluated is literally "true" or "false".

    private bool InitializeForProgramming()      //OK
    {
      if (J1939.getReplyStatus() == modJ1939.dmOpFailed)             //or OpComplete (dmBusy auto cycles)
      {
        //check the Pointer value to see if engineRunning, or already in Mode
        if (true)                                //let it proceed             ***  ??
        {
          //nothing to do
        }
        else
        {
          lblCommun.Text = "ProgramMode Failed!";
          lblCommun.ForeColor = Color.Red;

          //could report more detailed reasons! (engineRunning, etc.)
          return true;             //FAILED!
        }

      }

What is being evaluated here with the expression if(true)? If what is true?

Here is the original vb6 code:

Private Function InitializeForProgramming() As Boolean      'OK
If getReplyStatus = dmOpFailed Then             'or OpComplete (dmBusy auto cycles)
'check the Pointer value to see if engineRunning, or already in Mode
If (True) Then                                'let it proceed             ***  ??
  'nothing to do
Else
  txtCommun.Text = "ProgramMode Failed!"
  txtCommun.ForeColor = vbRed

  'could report more detailed reasons! (engineRunning, etc.)
  InitializeForProgramming = True             'FAILED!
  Exit Function
End If
End If

Please let me know if you need me to include anything else to help me get an answer.

like image 506
Mikkel Bang Avatar asked Feb 26 '26 04:02

Mikkel Bang


1 Answers

Most likely this is the result of a condition that was removed in the past. I.e. there used to be a condition in the if, but not any longer. You should check the source control history for changes to that line.

You can just remove the whole if statement in this case for your rewrite. Also C# probably complains that not all code paths return a value from the method.

like image 154
Joey Avatar answered Feb 28 '26 21:02

Joey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!