A Level Computing - COMP1 Programming





Blog Posts


Learning Programming

Learn Python on Codecademy

VB.Net Console Mode Guide is an excellent resource for when you are just starting to use the VB.net console system.  It will allow you to work over lots of examples and build upon your knowledge one step at a time.

Guide to Programming (VB) Tasks Booklet.pdf

Guide to Programming (VB).pdf



Data Types

All programming languages have data types. Many of these data types are standardised across languages.

NameSpecificationExample Use
IntegerA signed (positive or negative) 32-bit Whole numberYour Candidate number might be stored as an integer in a database
ByteA unsigned 8 bit bteStoring Binary Information, storing settings
Doublea 64 bit number, can be decimalPrices of stocks on the stock exchange maybe stored as doubles
charA Single CharacterStoring if someone is Male or Female
StringA serious of chars, enclosed in double quotes.Storing someone’s address
BooleanHas two options, true or falseStoring of someone wishes to receive emails
ENumAn ordered set of valuesStoring all the days of the week.
ArrayA collection of values of another data type, eg you could have an array or integers, or an array of doubles etc.Storing a collection of scores for a darts player.


Selection

Relational Operators

Relational Operators are operators that give a True or False answer. For example '=' is a relational operator, "Stephen" = "James" is clearly false, and "Stephen" = "Stephen" is true!

There are six common relational operators, these are:

Equal to (=)
Not Equal to (<>)
Greater Than (>)
Greater than or equal to (>=)
Less than(<)
Less than or equal to (<=)

Some examples of use are:

5  > 6        False
4 = 4         True
4 < 4         False
4 <= 4      True
4 <> 4      False
4 <> 5      True


The simple IF Statement

The simple IF Statment can be thought of as the diagram on the right. Where the condition that is being questioned is something involving one of the relational operators talked about above.

In the 'Do Something' Block there could be any code that you like, you could have calls to a function, you could have  a for loop, or just a simple two lines setting a varable.

Example.
IF var = 1 then
      var = 2

You could put another IF statment in the 'Do Something' Block, this called nested IF's because there is an IF within an IF. Say you were looking for a student called James out of thousands, you might start off by asking if the current student was male or female, then if they were male you could check to see if their name was "James"

if is a keyword in most languages and as such cannot be used as a variable name.


If-Then-Else

The If-THe-Else statement is slightly different, another flow chart is pictured below to show the differenceIf-Then-Else Flowchart.
An example of where you might use a If-Then-Else Statment might be if you were giving out instructions for a class, if the person you were handing too was a member or staff you would hand them special instructions, otherwise you would hand them normal instructions.


Case Statements

Case statments give you a list of options based on one variable, this can sometimes be easier than writing lots of If Statements, for example if you wanted to assign points based on age you might write the following code:

Select case age
   Case 16
       points = 5
   Case 17
       points = 10
   Case 18
       points = -5


So if age was 16, points would equal 5 after running this code, but if age was 18, points would equal -5 after running this code.


Repetition

One key advantage of computers is that they can do the same thing several times very very quickly.

As programmers you need to be able to instruct a computer to repeat a task without having to write it out lots and lots of times. for that we have loops.

There are three key types of loops that you need to know how to write

  • Loops that run a set number of times
  • Loops that run at least once
  • Loops that run under certain conditions

Loops that run a set number of times - These are your typical for loop. This could be for a count that increases or for each element in an array. A simple for loop that just outputs the numbers from one to ten is shown below.


Dim x as Integer
For x = 1 to 10
     Console.Writleline(x)
Next

As you can see, this is much easier than writing ten console.Writelines. now imagine if you needed one thousand numbers outputted, for loops save so much time!

Loops that run at least once - This loop runs, then checks a condition and decides as a result of the condition whether or not to the run the loop again.

Loops that run under certain conditions - This kind of loop is similar to the above, except the condition is checked before the loop runs at all, so theoretically the loop might not run at all. Think of this as an if statement that repeats until the condition is false