Presentation is loading. Please wait.

Presentation is loading. Please wait.

CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.

Similar presentations


Presentation on theme: "CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File."— Presentation transcript:

1

2 CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File names File names – Variable and object names Variable and object names Questions

3 All languages have a syntax composed of rules that specify the way the features can be manipulated to and process data and information. When code is written, it is often automatically checked by the application to see if the syntax rules have been met. If they have not, it will not run and will result in an error message.

4 Some of the fundamental elements are: – Special symbols (i.e. =, $, &, %, >, <, +) – Identifiers: names for variables, properties and functions. Often contains letters, digits, symbols, underscores but no spaces. – A command or instruction: a word that defines an activity to be performed by the program. – Reserved words: the words if, then, else, end, begin, for, array, true, false and so on are reserved words that are used by the language for special purposes. – Numbers and numerical operations symbols (+, /, x, -) – Characters and strings – Comments that describe the purpose or function of code

5 The basic instruction of any program is an assignment statement. Can you provide an example? An expression returns a calculated value that can be assigned to a variable or used in another expression or statement (e.g. Hours * Pay rate {Product of hours by pay rate}) Operators perform specific operations on various types of data. Some types of operators are: arithmetic operators (+, -, *, / etc.), Boolean operators (not, and, or), string operators (+ joins two strings) and relational operators (, =, =) Assignment statements and other statement structures can be treated as one instruction: a compound statement. Marked at the beginning or end by special symbols or reserved words (i.e. [...], {...}, BEGIN...END)

6 Special structures are used to control the processing pathway followed through the various parts of the program. There are three main types of structures that control: – The sequence of instructions to be executed. – The selection or branching of the instructions to be executed. – The iteration, or repetition, of instructions.

7 Sequence Programs execute the first line of code, followed by each subsequent line unless otherwise directed. Sometimes the program transfers the control to a block of code called a procedure or function. This occurs when a special function needs to be performed. Procedures and functions have previously been written in another part of the program. After they have been executed, the control is returned to the calling code. Procedures and functions perform tasks such as calculating as average, selecting some characters from a word or sorting a list of names.

8 Selection To make a program execute one block of code rather than another based on the result of a decision, we use a selection statement. For example, the calculation ‘one will be added to the total of boys’ will only be executed if the condition Sex = ‘Male’ is true: A two-branch structure is IF...THEN...ELSE...as shown by: A multiple-branch structure is frequently provided with a CASE or a SWITCH statement that can process more than two choices. A CASE structure is equivalent to a nested IF...THEN...ELSE structure.

9 For example, the calculation ‘one will be added to the total of boys’ will only be executed if the condition Sex = ‘Male’ is true: – IF Sex = “Male” THEN NumBoys = NumBoys + 1 Two-branch: – IF Sex = “Male” – THEN NumBoys = NumBoys + 1 {the condition evaluates to True} – ELSE NumGirls = NumGirls + 1 {the condition evaluates to False}

10 Iteration Also called repetition and looping. Executes statements repeatedly. The execution of the code is dependent on a condition being satisfied. Three types of repetition structure are: for-do, while-do and repeat-until (or do-while) loops. – For-do: repeat a segment of code a specific number of times. – While-do: performs a segment of code only if a nominated condition is true. The code will continue to be executed until the expression evaluates to false. Also called the pre-test loop. – Repeat-until: Also called post-loop and do-while loop. The code will always be executed at least once as the condition is tested only after the first pass through the code (such as 3-password entry system).

11 Need to be meaningful and consistent to make their use easier for the developer of the application. Also allows for easier modification, saving time and effort with fewer chances of mistakes. If using sensible names, there should be little chance of using a reserved word that has a special purpose (such as real, button, release, number, name and click).

12 File names Should include a reference to the type of data that is stored in the file, the version of the file and the purpose (i.e. HelloWorld programming example – 25 August 2011). The user should not need to open the file to ensure it is the correct one. File names should: – Be one word, or be joined by an underscore – Be only lowercase, or only have a capital for the first letter of each word – Not contain and symbols other than an underscore – Start with a letter – Be unique by making reference to the content, version and purpose.

13 Variable and object names Objects and variable names usually follow the following pattern with the first two being the minimum required: - The prefix indicates the type of object or the data stored (e.g. btn for button, int for integer, txt for text, vid for video clip and img for image). - The body describes the main purpose, such as calculate, name, animal. - The qualifier is a quality of the main purpose, such as first, tiger. - The suffix is additional information (e.g. 1, 2, 3, a, b, c, blue, green. Imganimallion3).

14 Questions 1) What occurs if syntax conventions aren’t met? 2) List and explain three fundamental elements. 3) Provide three examples of assignment statements you have used in your programming thus far. 4) What are four types of operators? 5) Describe the three control structures. 6) Why are naming conventions important? List your own example of a good file name.


Download ppt "CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File."

Similar presentations


Ads by Google