The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.
Same as in Delphi for Win32 but Prism also supports inline variable declaration.
function DoSomething : integer;
var
a, b : integer;
begin
a := 1;
b := 2;
var c : integer; //Prism allows inline (local) variables.
c := a + b;
result := c;
end;
Access VBA code blocks are surrounded by statement ending keywords that all use End such as End Sub, End If, and WEnd.
Sub x
End Sub
If x Then
End If
While x
WEnd
In .ASP html pages, you embed ASP code between <% and %>.
ASP Classic code blocks are surrounded by statement ending keywords that all use End such as End Sub, End If, and WEnd.
<%
%>
C# uses braces {} to indicate a code block of more than one line. For one line of code, the braces are optional.
I prefer to put the opening { and the closing } on their own line only because most of the examples I see do this. As opposed to C++, Java, and JavaScript where I put the opening bracket at the end of the first line (which I actually prefer).
int DoSomething()
{
int a = 1;
int b = 2;
return a + b;
}
For C++, Java, JavaScript, and PHP, I will use Berkeley indent style only because I see more C++ code formatted that way.
int Dog::Bark() { cout << "My first class method!" << endl; return 0;};
Same as standard C++. For C++, Java, JavaScript, and PHP, I prefer to put the first { at the end of the first line of the code block as in the example above because I see more C++ formatted that way.
class Cyborg {public: System::Void IntroduceYourself() { MessageBox::Show("Hi"); }};
ObjectPAL code blocks are surrounded by statement ending keywords that all use End with camel caps such as endMethod, endVar, endIf, endSwitch, and endTry.
method
endMethod
endVar
if
endIf
switch
endSwitch
try
endTry
Object Pascal requires the semi-colon after the "declaration" part.
a, b : integer
result := a + b;
Curly braces are used to bracket code blocks including classes and the methods within a class.
For Java, JavaScript, PHP, and C++, I prefer to put the first { at the end of the first line of the code block as in the example above because I see moreJava codeformatted that way.
public class Dog {
public bark() {
System.out.println("Ruff");
In html pages, you embed JavaScript code between <script> and </script> (see example). Also it's tradtional to put an HTML comment around your code too so that really old browsers don't crash (probably not all that important these days).
For JavaScript, Java, PHP, and C++, I prefer to put the first { at the end of the first line of the code block as in the example above because I see moreJavaScript codeformatted that way.
<script language="JavaScript" type="text/javascript">
<!--
function DisplayDialogLg(StrURL) {}
if (x == -1) {
-->
</script>
In Perl, you create the entire HTML page within your .PL script file using print commands.
For Perl, PHP, JavaScript, Java,and C++, I prefer to put the first { at the end of the first line of the code block as in this example because I see morePeal codeformatted that way.
$x = "Yes";
If ($x == "Yes") { print "Hello world";
print "I am a Perl coder.";
In .PHP html pages, you embed PHP code between <?PHP and ?>.
For PHP, JavaScript, Java,and C++, I prefer to put the first { at the end of the first line of the code block as in the example above because I see morePHP codeformatted that way (and on PHP.Net).
Although I don't like to use it, PHP offers an alternative syntax for if, while, for, foreach, and switch. These code blocks are surrounded by statement ending keywords that all use End with camel caps such as endif, endwhile, endfor, endforeach,and endswitch.
<?PHP
//Simple if
If ($x == "Yes") echo "hello world";
//If with a block of code.
If ($x == "Yes") { echo "Hello world";
echo "I am a PHP coder!";
?>
VB Classic code blocks are surrounded by statement ending keywords that all use End such as End Sub, End If, and WEnd.
VB.Net, like VB Classic code blocks, are surrounded by statement ending keywords that all use End such as End Class, End Sub, End Function, and End If.
Public Class Dog
End Class
Protected Sub MySub
Public Shared Function MySharedFunction() As Integer MySharedFunction = 12345End Function