U2a - Programming Basics Flashcards
Define data type
The kind of values that can be used in a data item.
Name 5 data types
Integer, float/real, character, string, boolean
Define arithmetic operator
A symbol that will perform an operation on numbers e.g. +, -
What do constants look like?
They’re typically shown in uppercase and the words are separated with an underscore, eg. MIN_AGE
This is known as snake case.
Why declare a constant instead of a variable?
This prevents the value from being changed accidentally by a part of a code. It shows a programmer that the value should stay the same throughout the program.
Can a constant ever change its value?
A constant cannot be changed when the program is running. However, a constant can be changed by a programmer before the program is compiled or translated.
What is used to convert data types? (AKA Casting)
Functions
Why should you use comments in your programs? (3)
- To describe the purpose of the program
- To state the author of the program
- To explain what the code does
Define sequence
Statements are executed one by one in the order they are written
Define selection
An IF statement is a selection statement. The next statement to be executed depends on whether the condition being tested is True or False
Comparison operators
= equal to
=/ not equal to
> greater than
< less than
Define iteration
Iteration means repetition of a section of code
Three types of iteration statement
- FOR..ENDFOR
- WHILE…ENDWHILE
- REPEAT…UNTIL
When would you use a for loop
When you want to execute the loop a specific number of times
When would you use a while loop
When you want to execute the loop while a certain condition is true
When would you use a repeat until loop
When you want to execute the loop until a certain condition is true
Define an array
A data structure that allows you to hold many items of data which is referenced by one identifier
Do all items of data in the array have to be the same data type?
Yes
How would you find an array’s length?
LEN(array)
How would you add red to an array?
array[index e.g. 0]
Which out of lists and arrays have a fixed length?
Arrays
How can you add more items to an array?
You would need to create a new larger array and copy the items across
How does a linear search work?
Each item is examined in sequence until the item is found or the end of the list is reached.
How does a bubble sort work?
- Each item in a list is compared to the one next to it, and if it is greater, they swap places
- At the end of one pass through the list, the largest item is at the end of the list
- This is repeated until the items are sorted