Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "if (1)" do?

Tags:

perl

What does the syntax

if (1) {}

do?

I can't find documentation for this syntax and 1 is not being treated as a boolean. Am I right?.

like image 427
user2521358 Avatar asked Jul 08 '13 15:07

user2521358


1 Answers

Technically, the if (1) does nothing interesting, since it's an always-executed if-statement.

One common use of an if (1) though is to wrap code you'd like to be able to quickly disable, say for debugging purposes. You can quickly change an if (1) to if (0) to disable the code.

like image 82
Joe Z Avatar answered Sep 23 '22 06:09

Joe Z