0% found this document useful (0 votes)
6 views

9 1 Programming Basics 1

Uploaded by

lamywamy
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

9 1 Programming Basics 1

Uploaded by

lamywamy
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

9.

1 Programming basics
Unit 9 Computing Concepts

Icons: Flash activity (these are not editable) Useful web links in the Notes Page

Teacher’s notes in the Notes Page Worksheet or support sheet available

1 of 19 © Boardworks Ltd 2013


Curriculum
This presentation links sections
supports the following
of the Programme of Study for KS3 Computing:

use two or more programming languages, at least one of


which is textual, to solve a variety of computational problems;
make appropriate use of data structures such as lists, tables
or arrays; design and develop modular programs that use
procedures or functions

This presentation supports the following areas of knowledge


in the Naace Curriculum Framework for KS3 ICT:

Technical Understanding – Programming and control

2 of 19 © Boardworks Ltd 2013


Learning objectives

By the end of this presentation we will have learned:

to understand how computers process


code (instructions)
to recognize the difference between
constants and variables
to create simple IF statements
to understand control flow.

3 of 19 © Boardworks Ltd 2013


Programming basics

Computers will only do what you


tell them to. If a program doesn’t
work, you haven’t given it the
right instructions!




In order to program a computer,


you need to speak in a language
that it understands. There are
many different programming
languages, but their basic
concepts are the same.

4 of 19 © Boardworks Ltd 2013


Robby the robot

5 of 19 © Boardworks Ltd 2013


Common elements of programming

In order to start programming we need to understand some


of the common elements of all programming languages:
constants variables control flow.
Constants stay the same throughout the running
(or execution) of the program.
An example of a constant might be the speed of a character.

My speed
is set to 5.
My speed is
set to 11.

When the user moves the character, it always


moves at the same speed.
6 of 19 © Boardworks Ltd 2013
Constants

Another example of a constant is when a user is asked to


enter their name at the beginning of a game.

The name ‘Sam’ stays the same throughout the game.


7 of 19 © Boardworks Ltd 2013
Variables

Variables store values that change


throughout the execution of a program.
They can hold any value; it could be a
calculation, a response or something else.
First we will look at variables that store
calculations. Look at the example below:

tells the computer that we want to


assign something to ‘a’

a = 1+1
the name of the number that
the variable will be stored in ‘a’
8 of 19 © Boardworks Ltd 2013
Variables in games

A variable changes throughout the execution of the program


depending on different conditions.
For example, the score in a game
changes often. It will start at 0 and
then increase at different stages.
Here is a variable called ‘score’.
At the beginning of the program
it holds the value 0.

score=0
If you gain 10 points for every target you hit, the variable will
change by 10.

9 of 19 © Boardworks Ltd 2013


Variables in games

The pseudocode for adding 10 to the variable ‘score’ is this:

This is pseudocode,
a way of planning out our
score=score+10 code before converting it
to the chosen
programming language.

This means add 10 to


whatever number is in ‘score’.

10 of 19 © Boardworks Ltd 2013


Assigning numbers to variables

Look at the variable assignment statement below.

b=4*3
What number has been assigned to ‘b’?

The answer is:

b=12

If a calculation is assigned to a variable then the variable


always contains the answer, not the calculation.

11 of 19 © Boardworks Ltd 2013


What is the value of the variable?

12 of 19 © Boardworks Ltd 2013


Variables and responses

Variables aren’t always numbers. You might have a variable


that gives the user a response.

For example, if you want to tell the


user that they are correct or
incorrect, we would assign the
variable like this:

We use speech marks


response=“ ” when we are entering
text in programs.

Then, during the code we can change the variable to give


the user a response.

13 of 19 © Boardworks Ltd 2013


Variables and responses

In this example, ‘10’ is the correct answer. Below is an


IF statement to assign the right response to the
variable depending on the answer given.

IF answer=10 THEN
response=“Correct!”
ELSE
response=“Incorrect!”
ENDIF

10 Correct!

14 of 19 © Boardworks Ltd 2013


Constant or variable?

15 of 19 © Boardworks Ltd 2013


Making decisions

Instructions aren’t always step-by-step.


Sometimes you need a program to make
decisions based on certain information.
This is called control flow.
For example, a game might have two levels:
beginner and advanced. You could use an
IF statement to say what will happen when
different options are selected.

IF beginner is selected THEN


play beginner level
ELSE
play advanced level
ENDIF
16 of 19 © Boardworks Ltd 2013
Do you understand this IF statement?

The variable ‘a’ contains the number 4.

IF a<10 THEN
sound alarm
ELSE
flash the lights
ENDIF

What will happen if this code runs?


The alarm will sound.
17 of 19 © Boardworks Ltd 2013
IF statements

18 of 19 © Boardworks Ltd 2013


AFL check

How did you do?


Copy the actions below to show how much you agree with
the statements.

I understand how computers process code.


I recognize the difference between constants and variables.
I can create simple IF statements.
I understand the term ‘control flow’.

19 of 19 © Boardworks Ltd 2013

You might also like