- Expressions to assign values to variables
- Expressions to return values using arithmetic operations (+, -, *, /, ^, mod)
- Execution of lines of code in sequence demonstrating input – process- output
- Expressions to concatenate strings and arrays using the & operator
- Use of selection constructs including simple and complex conditional statements and logical operators.
- Iteration and repetition using fixed and conditional loops Pre-defined functions (with parameters)
All code examples are given in Visual basic. You can find more about this topic in chapter 2 of “How to Pass NATIONAL 5 Computing Science”
Expressions to assign values to variables
The end result of an expression represents a value, which is typically of a familiar data type such as Boolean, String, or a numeric type.
Name="Bob the Builder"
Age=16
Expressions to return values using arithmetic operations (+, -, *, /, ^, mod)
The end result of an expression represents a value, which is typically of a familiar data type such as Boolean, String, or a numeric type.
msgbox(length*breadth)
squared=x^2
remainder=11 mod 2
perimeter=2*length+2*breadth
Execution of lines of code in sequence demonstrating input – process- output
Procedural languages follow a predetermined sequence. The program below shows Input, Process and output
name=inputbox("What is your name") 'input upperName=upper(name) 'process msgbox("your name in capitals is " & upperName) 'output
Expressions to concatenate strings and arrays using the & operator
Concatenation is the joining together of two or more strings. Array’s can also be concatenated into strings.
fullName=firstName & lastName
Use of selection constructs including simple and complex conditional statements and logical operators.
conditional statements use comparators (Comparison Operators) like >,<,=,<>
Logical operators are used make the comparison more complex AND, OR, NOT
If score>=1000 then msgbox("well done")
if time>12 and hungry=true then msgbox("Lunchtime")
Iteration and repetition using fixed and conditional loops
The terms iteration and repetition are essentially the same thing in programming. They describe the repeated execution of a block of statements. A repetition or iteration structure is a loop statement. It repeats a block of statements once, multiple times or not at all. It all depends on the loop condition and when this condition is tested.
For Counter= 1 to 5 ' fixed loop msgbox(counter) next
Do 'conditional loop quit=msgbox("Do you want to quit?",vbYesNo) loop until quit=vbYes
Pre-defined functions (with parameters)
A pre-defined function is a function that is built into the programming language. Examples include Sin, Cos & Tan
capsName=upper(name)
dice=int(rnd()*6)+1
Exemplification of functions
Hexagon(n) Repeat 6 Times Move (n) Rotate (60) End Repeat