< GCSE Computing

Starter

The following examples fit the structure of GCSE Computing The code has been written in VB(.net) and C#(.net) In c# // and in VB ' are comments and are ignored by the compiler. They are there to help you.

Programming Language Rules

Every programming language has its rules. Its the main difference between them. A lot of them have some of the same rules.

C#

must be used at the end of each line of code (to continue the line to the next line don't use the ;)

{} must be used to enclose code

VB

To continue the line to the next line use _ The code encloses vary

Declaring a variable

C#

//(type e.g. int or string) (name e.g. i); int i; //integer called i (instead of VBs optional as ... C# uses type object for any type)

VB

dim i as integer //integer called i (as integer optional)

IF Conditions

C#

if (Condition e.g. 1=1) {

 //Do something if true

}else{

 //Do something if false

}

VB

if Condition e.g. 1=1 then

 'Do something if true

else

 'Do something if false

end if

Loops

For Next

C#

int i; //Declare i For (i=0; i<10, i++) {

 //i is an integer variable and the for checks if i = 10 every loop. If not does the process within then adds 1 to i.

}

VB

For i As Integer = 1 To 10

  'i is an integer variable and the for checks if i = 10 every loop. If not does the process within then adds 1 to i.

Next i

While

C#

int i; While(i<10) //Checks if i less than 10 {

 //Loops till i = 10
 i++; //Adds 1 to i

}

VB

dim i While i<10 'Checks if i less than 10

 'Loops till i = 10
 i+=1 'Adds 1 to i

End While

Repeat(loop)

C#

While(true) {

 //Does this for as long as the program is open

}

VB

Do

 'Does this for as long as the program is open

Loop

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.