Comprehensive Fundamentals of Programming: Control Structures, Data Types, and Variable Assignment
Core Programming Control Structures
Sequencing
- Sequencing is a control structure where all instructions are performed in sequential order and executed one at a time.
- The computer runs the code strictly in order, one instruction at a time from top to bottom, to achieve an intended goal.
Selection
- Selection is a generic term for a programming statement that uses a specific condition to determine whether a block of code or behavior is executed or skipped.
- It allows the program to choose different execution paths based on evaluated boolean criteria.
Iteration
- Iteration refers to a structure containing a block of code that repeats execution continuously or conditionally until a specific goal or termination condition is met.
Primitive Data Types
Numbers
- Composed of numerical digits from to .
- Can represent whole numbers (integers) or decimals (floating-point numbers).
- Can be positive or negative values.
- Must be written without surrounding quotation marks.
Strings
- A sequence of arbitrary characters, including letters, digits, symbols, and spaces, combined together into words, sentences, or structured text.
- Enclosed in single or double quotation marks (e.g.,
"Hello","Hello!","This is fake").
Booleans
- A logical data type that can take only one of two possible values:
trueorfalse. - Written directly without quotation marks.
- A logical data type that can take only one of two possible values:
Variables and Memory Mechanics
Container Metaphor
- Variables act as containers stored in memory, each designed to hold information.
- When stored information is required later in a program, the container is referenced directly by its designated variable name.
Naming Rules and Capacity Limits
- Variables can be given arbitrary custom identifier names.
- Each individual variable can hold exactly one value at a time.
Variable Assignment Examples
- Numeric variable creation:
My Money = 3.5,Value <- 6.78 - String variable creation:
Word = "Hello",Sentence = "This is fake" - Boolean variable creation:
flag = true,IsItFinished = false
- Numeric variable creation:
Right-to-Left Assignment Evaluation
- In any assignment statement, the expression located on the right side of the assignment operator is always fully evaluated first.
- Once the expression on the right is computed, the resulting value is assigned and stored into the variable located on the left side.
- Overwriting rule: If a value is already stored in the destination variable, that prior value is cleared out (dumped), and the newly calculated value replaces it.
Operators and Expressions
Standard Arithmetic Operators
- Addition:
+ - Subtraction:
- - Multiplication:
* - Division:
/
- Addition:
Operator Precedence (BODMAS / BIDMAS)
- Mathematical evaluation inside code follows standard rules of precedence: Brackets/Orders first, followed by Division/Multiplication, and finally Addition/Subtraction.
- Evaluation example:
Advanced Operators
- Modulus (
modor%): Computes the remainder of a division operation between two numbers. - Logical Operators: Includes
AND,OR, andNOTfor evaluated logical operations.
- Modulus (
String Concatenation
- The
+sign acts as the primary operator when applied to string data types. - When the
+operator appears between two strings, or between a string and a number, it performs concatenation, joining the values together into a single continuous string. - Concatenation example:
"fizz"+"buzz"evaluates to"fizzbuzz".
- The
Execution and Variable Tracing Reference
Arithmetic Expressions
Sequential State Tracing Examples
Basic variable sequence:
State tracking for
MYNUM:Initial assignment:
Re-assignment expression:
Compound evaluation:
Direct update:
Multi-variable state record:
Updated variable equations: