Difference between revisions of "Block Syntax"

From Exterior Memory
Jump to: navigation, search
(Created page with "==Block Syntaxis== C syntax with starting bracket on same line as the conditional statement: if (x==3) { echo "three!"; return; } C syntax with the starting brac...")
 
Line 28: Line 28:
 
  end;
 
  end;
  
PHP (deprecated), shell syntax: using endif (or fi) as end statement, if automatically implies begin of a block:
+
Shell syntax: use if/fi:
 +
 
 +
if [ $x -eq 3 ]
 +
then
 +
    echo "three!";
 +
    return 0;
 +
fi
 +
 
 +
PHP (deprecated): using endif (or fi) as end statement, if automatically implies begin of a block:
 
  if (x===3) :
 
  if (x===3) :
 
     echo "three!";
 
     echo "three!";

Revision as of 22:52, 20 March 2012

Block Syntaxis

C syntax with starting bracket on same line as the conditional statement:

if (x==3) {
    echo "three!";
    return;
}

C syntax with the starting bracket aligned with the closing bracket:

if (x==3)
{
    echo "three!";
    return;
}

C syntax, with Whitesmiths style C indentation, arguing that { and } are not part of the if statement:

if (x==3)
    {
    echo "three!";
    return;
    }

Pascal Syntax: begin and end instead of { }:

if (x=3) then
begin
    echo "three!";
    return
end;

Shell syntax: use if/fi:

if [ $x -eq 3 ] then

   echo "three!";
   return 0;

fi

PHP (deprecated): using endif (or fi) as end statement, if automatically implies begin of a block:

if (x===3) :
    echo "three!";
    return;
endif;

Python syntax: indentation implies nesting, no need for end or } syntax:

if (x==3)
    echo "three!"
    return