Kamis, 18 Desember 2008

Display "Hallo World" with Pascal Language

The very simple program of Pascal Programming. This program will display "Hallo World" and waiting input from user.

Program Lesson1_Program1; {Program caption}
Begin {no semicolon}
Write ('Hallo World');
Readln; {waitting from input user}
End.

After we run this program it will be give an output:

Hallo World

and waiting input from user.

Note : this syntax can be copy and paste to the notepad or

other text editor and save it with extention .pas (eg:

HalloWorld.pas)

Program
Folowing the title of the program.

Write()
Function to display the statemant ('Hallo World' in this case). If we want to display and the pointer go to the next line we can use Writeln().

Readln;
Waiting for user input.

{...}
A comment line. If we run the program it will be ignore it.

; (semicolon)
End every function which we are write before.

End.
Close the body of program when start with begin.


Other process of writting of this syntax:

Program Lesson1_Program2;begin
Write('Hallo World');Readln;End

This program also runs perfectly as the previous one. The only dfference is neatness and friendliness.

Display "Hallo World" with C# Language

This is the very simple program of C# language. It will display "Hallo World" and waiting input from user.

// Namespace Declaration

using System;

// Program start class
class Hallo_World
{
// Main begins program execution.
static void Main()
{
// Write to console
Console.WriteLine("Hallo World");

// Make window wait for input
Console.ReadLine();
}
}


After we run this program it will give an output:

Hallo World

And waiting input from user to terminate the program.



using system;
Indicates that we are referencing the System namespace. Namespaces contain groups of code that can be called upon upon by C# programs.
With the using System; declaration, you are telling your program that it can reference the code in the System namespace without pre-ending the word System to every reference.

class WelcomeCSS
The class declaration, contains the data and method definitions that your program uses to execute. Can use to decribe objects, such as structs, interfaces, delegates, and enum.
This particular class has no data, but it does have one method.

Main
The methed of class WelcomeCSS tells what this class will do when executed. It is the starting point of a program. Often called "entry point" If we recive the error message saying that it can't find the entry point, it means that we tried to compile an executable program without a Main method.

static
A static modifier preceeds the word Main, meaning that this method works in this spedific class only, rather than an insatne of class.
This is necessary, because when a program begins, no object instances exit.

void
Every mthod must have a return type. In this case it is void, means that Main doesnt return a value.

WriteLine(...)
Console is a class in the System namespace. WriteLine(...) is a methode in the Console class.
We use the ".", dot, operator to separate subordinate program elements.
Note that we could also write this statement

//
This is a single line comment mark, mean that they are valid until the end-of-line. For multiple lines use /*(statement)*/
Comment are ignore when we compile our program.

All statements end with a ";", semi-colon. Classes and methods begin with "{", left curly brace, and end with a "}", right curly brace. Any statements within and including "{" and "}" define a block. Blocks define scope (or lifetime and visibility) of program elements.

Console.ReadLine();
Waiting input from user.