programming theory 1
TRANSCRIPT
-
7/28/2019 Programming Theory 1
1/3
Vocabulary
Statement Instruction to be executed. Think Command in command prompt.
Python 3.x Example:print ('Hello, world!')Output:Hello, world!
Comment Part of a code that is ignoredby the program during execution. Used to add notes inthe code.
Python 3.x Example:#This is a comment
XHTML example
In my pseudocode Ill be using two forward slashes for comments, as in:
//This is a comment in my pseudocode
Identifier A name assigned to a variable or subroutine. Most languages have rules as to whatyou can assign as an identifier.
In Python 3.x, identifiers must start with either a letter or an _ (underscore), andcan contain any number of letters, underscores and numbers.
Variable An item used for data storage.
Constant A variable that is not to be altered during the execution of a program.
Reserved A keyword that cannot be assigned as an identifier due to its special use inWord a language. Reserved words depend on language.
Data type The type of a piece of data. Most common are String, Integer and Boolean.
Python 3.x Example:type('Hello, world!')Output: //That is a string
type(1337)
Output: //That is an integer
type(True)Output: //That is Boolean
Selection Used to allow a program to execute one of different pieces of code basedConstruct on whether a condition is true. Most common are the If-Then-Else construct and the
Switch statement (no major difference between the two.)
Iteration/ Used for repetition of code; also known as aloop. One repetition of the
Repetition code is known as an iteration. Most common types of loops:Construct
While Loop
Do While/Repeat Until Loop
For Loop
-
7/28/2019 Programming Theory 1
2/3
Subroutine A self-contained piece of code, i.e. only executed when called by another part of thecode. Used when the same block of code needs to be used in different parts of theprogram so it is not necessary to take up space by writing the same code again, butinstead just calling it whenever it is needed.
Procedure A subroutine that, unlike a function, does not return a value.
Function A subroutine that returns a value after execution. Think f(x) in mathematics. The
function is defined, and then one can enter a value into the function to receive aresult. Often used interchangeably with procedure.
Maths example:f(x) = x*3f(3) = 9
Pseudocode example:Functionf(x) //f is just an identifier. It could be anything.
result = number*3 //This assigns a value to variable result
Return result //Returns a value, unlike a procedureEnd Function //Signifies the end of the function
numberUser Input // indicates inputprint f(number) //Calls the function and prints the return value (result)
If we assume user input is 3 (x 3), output will be 9.
More on data types
In each language, there can be dozens of different data types, and in many it is possible to create
custom data types. It would be extremely pointless to go over every data type so I will go over themost basic. Most other data types are composites of these ones.
Type name Description Range/Example
Byte 8-bit integer -127 to +127 or 0 to 255
Char Single ASCII or UnicodeCharacter
A orG or5
Boolean Binary Data True or False
In most languages Boolean is represented as True/False. In lower levels it can be represented as1 or 0, where 1 is True and 0 is False. In higher levels in can be used for specific cases (Wikipediaextract):
the outcome of an experiment ("success" or "failure")
the response to a yes-no question ("yes" or "no")
presence or absence of some feature ("is present" or "is not present")
Common composite data types can include:
Type name Description Range/Example
Integer 32-bit integer (usually) -2,147,483,647 to+2,147,483,647 or 0 to
4294967295Long 64-bit integer (usually) You get the memo
Float 32-bit decimal (usually) 0.00001 or 35.12254Double 64-bit decimal (usually) You get this memo too
String Sequence of Characters Hello, world! or asdf123
-
7/28/2019 Programming Theory 1
3/3
Sources
http://en.wikipedia.org/wiki/Control_flowhttp://en.wikipedia.org/wiki/Iterationhttp://en.wikipedia.org/wiki/Binary_datahttp://www.ashishpaliwal.com/blog/2009/08/if-else-vs-switch-%E2%80%93-which-is-better/http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
http://www.amazon.com/Cambridge-International-Computing-Coursebook-Examinations/dp/0521186625
http://en.wikipedia.org/wiki/Control_flowhttp://en.wikipedia.org/wiki/Control_flowhttp://en.wikipedia.org/wiki/Iterationhttp://en.wikipedia.org/wiki/Iterationhttp://en.wikipedia.org/wiki/Binary_datahttp://en.wikipedia.org/wiki/Binary_datahttp://www.ashishpaliwal.com/blog/2009/08/if-else-vs-switch-%E2%80%93-which-is-better/http://www.ashishpaliwal.com/blog/2009/08/if-else-vs-switch-%E2%80%93-which-is-better/http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.htmlhttp://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.htmlhttp://www.amazon.com/Cambridge-International-Computing-Coursebook-Examinations/dp/0521186625http://www.amazon.com/Cambridge-International-Computing-Coursebook-Examinations/dp/0521186625http://www.amazon.com/Cambridge-International-Computing-Coursebook-Examinations/dp/0521186625http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.htmlhttp://www.ashishpaliwal.com/blog/2009/08/if-else-vs-switch-%E2%80%93-which-is-better/http://en.wikipedia.org/wiki/Binary_datahttp://en.wikipedia.org/wiki/Iterationhttp://en.wikipedia.org/wiki/Control_flow