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 00 to 99.
    • 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: true or false.
    • Written directly without quotation marks.

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
  • 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: /
  • 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: L=30×E−108L = 30 \times E - 108
  • Advanced Operators

    • Modulus (mod or %): Computes the remainder of a division operation between two numbers.
    • Logical Operators: Includes AND, OR, and NOT for evaluated logical operations.
  • 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".

Execution and Variable Tracing Reference

  • Arithmetic Expressions

    • 1+5=61 + 5 = 6
    • 15×3=115≈0.0667\frac{1}{5 \times 3} = \frac{1}{15} \approx 0.0667
    • 542211≈0.0244\frac{54}{2211} \approx 0.0244
    • 22012017≈1.0912\frac{2201}{2017} \approx 1.0912
  • Sequential State Tracing Examples

    • Basic variable sequence:

    • x=10x = 10

    • y=x+5=10+5=15y = x + 5 = 10 + 5 = 15

    • z=50z = 50

    • State tracking for MYNUM:

    • Initial assignment: MYNUM=2\text{MYNUM} = 2

    • Re-assignment expression: MYNUM=2×15=30\text{MYNUM} = 2 \times 15 = 30

    • Compound evaluation: MYNUM=10+MYNUM×2=10+(30×2)=10+60=70\text{MYNUM} = 10 + \text{MYNUM} \times 2 = 10 + (30 \times 2) = 10 + 60 = 70

    • Direct update: MYNUM=51\text{MYNUM} = 51

    • Multi-variable state record:

    • A=2A = 2

    • Z=3Z = 3

    • B=5B = 5

    • C=5C = 5

    • DEN=1015\text{DEN} = 1015

    • BE=27\text{BE} = 27

    • Fizz=11\text{Fizz} = 11

    • Buzz=85\text{Buzz} = 85

    • Updated variable equations:

      • x=120x = 120
      • A=Z−A+X−AA = Z - A + X - A
      • K=E×A×XK = E \times A \times X