Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

364
Visualizações
Why use : instead of { in if statements

Why do people use

if(condition) :
    /*do something*/
else:
    /*do something else*/
endif;

instead of

if(condition) 
{
    /*do something*/
} 
else
{
    /*do something else*/
}

Is one better than the other in any way? What should i get use to too?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This falls in the category of coding style. Some people like to use brackets some like to use the ":end..." notation. The advantage to the latter is more towards using PHP conditionals and loops where there is output to HTML. For example,

//Pure PHP with brackets
<?php
if ($condition) {
   echo "output";
}?>

//PHP and HTML with brackets
<?php
if ($condition) {?>
   output
<?php } ?>

//PHP and HTML with ":end..." notation
<?php if ($condition):?>
   output
<?php :endif ?>

Some people prefer the last as the ":endif" gives a clue what opening construct to look for when matching control structures. The bracket could match any other bracket but an ":endif" can only match and "if" construct. You can use either it is up to your style.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda