Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pseudocode Key Revision Points.

Similar presentations


Presentation on theme: "Pseudocode Key Revision Points."— Presentation transcript:

1 Pseudocode Key Revision Points

2 NOTE The basic syntax you’ll need in your exam is provided in this presentation Practice writing pseudocode is just as (more!!!) important than knowing the syntax Use the past paper practice questions provided to develop your skills!

3 PSEUDOCODE Used by programmers to write algorithms/ plan programs
Not a real programming language (although it contains “program like” syntax) Can be translated into any programming language

4 INPUT/OUTPUT Equivalent to input and print in Python. Don’t forget input always needs to be assigned somewhere i.e. a variable OUTPUT “Hello Bert” OUTPUT “Which way do you want to go?” direction  USER INPUT Distance  INT(USER INPUT)

5 ASSIGNMENT Use an arrow to indicate assignment. Equivalent to using a single = sign in Python Arrow always points to the left! Indicating the variable type is optional but if in doubt do it! INT x  42 STRING user  “Bert” CHAR initial  ‘A’ BOOL gameOver  TRUE STRING choice  USER INPUT INT choice  INT(USER INPUT)

6 CONDITIONALS Equivalent to if/elif/else in Python Must have an END IF
Example: IF name = “Bert” THEN OUTPUT “Hello Bert” ELSE IF name = “Fred” THEN OUTPUT “Hello Fred” ELSE OUTPUT “Who are you?” END IF Note the single = sign in if/elif part. It’s the comparison operator NOT the assignment operator. Equivalent to == in Python

7 NESTED CONDITIONALS Must have two (or more) END IF statements – one for each IF Example: IF age < 18 THEN OUTPUT “Discount” ELSE IF age > 65 THEN OUTPUT “Full price” END IF

8 ITERATION - FOR Python – for i in range(0,10):
Pseudocode – FOR i  0 TO 9 DO Code inside the for block should be indented Don’t forget END FOR For nested loops you need multiple END FORs

9 ITERATION - WHILE Python: while x<=100:
Pseudocode: WHILE x <= 100 DO Code inside the for block should be indented Don’t forget END WHILE For nested loops you need multiple END WHILEs

10 ARRAYS Indexing can start at 0 or 1. AQA often uses 1. Examples below make this assumption Declare and initialise an array INT myArray  [5,3,2,7] Reassign values in an array myArray[2]  6 myArray[3]myArray[3]+4 Access values in an array OUTPUT myArray[1] myNum  myArray[2]

11 2D ARRAYS Indexing can start at 0 or 1. AQA often uses 1. Examples below make this assumption Each element has a “row” and “column” index Declare and initialise a 2D array INT my2DArray  [[5,3],[2,7],[4,1]] Reassign values in an array my2DArray[2][1]  6 my2DArray[3][2]my2DArray[3][2]+4 Access values in an array OUTPUT my2DArray[1][2] myNum  my2DArray[2][2]

12 ARRAY NOTE There is no pseudocode for appending to (or deleting from) an array By definition an array’s size is fixed at declaration – you can’t add more elements

13 FUNCTIONS Must have at least one RETURN Don’t forget END FUNCTION
Include the parameters and type Code inside function should be indented FUNCTION getArea(INT width, INT height) INT area  width * height RETURN area END FUNCTION

14 PROCDEURES Does NOT have a RETURN Don’t forget END PROCEDURE
Include the parameters and type Code inside procedure should be indented Can use PROC instead of procedure PROCEDURE showArea (INT area) OUTPUT “The area is “ + STR(area) END PROCEDURE


Download ppt "Pseudocode Key Revision Points."

Similar presentations


Ads by Google