If target (true)

I've seen code written like this:

if (true) {
... // do something
}

      

Why would you want to do something like this? Is there something special about this structure?

thank

+3


source to share


3 answers


Pretty much any modern compiler will simply optimize this. I'm guessing someone put it in there during development to allow them to easily delete the block of code (by changing true

to false

) and either forgot or didn't bother to delete it when they were done.



+3


source


This is one of many ways to segment code during testing / development. Many may debate if this is really good coding practice, but it can be a quick and convenient way to split up your code. It is also a quick way to execute the code that follows the complex conditional statement that you want to test.

You can use it like this:



/* if (my_comlex_or_rare_conditional_case) then */
if (true) then
{
 lots of code here....
} /*End if */

      

+2


source


There were times when I added true ||

or false &&

inside a condition to force it to branch and test the code - but only during development. The code you posted doesn't need an if condition.

+1


source







All Articles