1. Inner Count-Controlled Iteration Theory
When you place one loop inside another, it is called nesting. The most critical rule for students to remember is that the inner loop must complete all of its iterations before the outer loop can move to its next step.
FOR i β 1 TO 3
FOR j β 1 TO 2
OUTPUT i, j
NEXT j
NEXT i
Tracing this results in: (1,1), (1,2) then (2,1), (2,2) and finally (3,1), (3,2).
2. Programming Constructs Fundamentals
Every program, no matter how complex, is built from three building blocks:
- Sequence: Instructions followed in order.
- Selection: Decisions (IF/CASE).
- Iteration: Repeating steps (Loops).
3. Variables: Declaration & Initialization Storage
A variable is a named location in memory. Before using one, you should declare it (tell the computer it exists) and initialize it (give it a starting value, like 0).
DECLARE score : INTEGER score β 0 // This is initialization
4. Arithmetic Operators (^, MOD, DIV) Calculations
In programming, we often need to divide numbers in special ways:
DIV: Quotient (How many whole times it fits). Example: 7 DIV 2 = 3.
MOD: Remainder (What is left over). Example: 7 MOD 2 = 1.
MOD: Remainder (What is left over). Example: 7 MOD 2 = 1.
5. Switch Case to IF Conversion Selection
A Switch/Case is best for checking one variable against many values. However, IF statements are more powerful because they can check ranges (like score > 50).
IF day = 1 THEN OUTPUT "Monday" ELSEIF day = 2 THEN OUTPUT "Tuesday" ELSE OUTPUT "Invalid" ENDIF
6. 2D Array Output Data Structures
To output a 2D array (like a grid or table), you must use nested loops. The outer loop usually handles the rows, and the inner loop handles the columns.
, [0,1], [1,0], [1,1]]
FOR r β 0 TO rowCount - 1
FOR c β 0 TO colCount - 1
OUTPUT grid[r, c]
NEXT c
NEXT r
7. While Loop Tracing Iteration
A WHILE loop is condition-controlled. You must check the condition before every cycle. If the condition is false initially, the code never runs.
8. Core Datatypes Data
Programs must know what kind of data they are handling:
- Integer: Whole numbers.
- Real/Float: Decimals.
- Boolean: True/False.
- String: Text.
9. Parameter Passing Subroutines
Parameters are values you pass into a subroutine so it can perform work on them. This makes code flexible and reusable.
SUBROUTINE calculateArea(width, height) OUTPUT width * height ENDSUBROUTINE
10. List Processing Arrays
Processing a list (1D array) requires a loop that goes from index 0 to the end of the list. We use the index variable to look at each item one by one.
11. Syntax vs Logic Errors Debugging
Syntax Error: The "grammar" is wrong. Program won't run. (e.g.,
Logic Error: The program runs but gives the wrong answer. (e.g.,
Iff x = 5)Logic Error: The program runs but gives the wrong answer. (e.g.,
area = w + h)
12. Functions vs Procedures Subroutines
A Procedure just carries out instructions. A Function must RETURN a value back to the main program.
13. Benefits of Subroutines Software Design
Why use subroutines? It makes code:
- Easier to read (Modular).
- Easier to test and debug.
- Reusable in different parts of the program.
14. Count-Controlled (FOR) Logic Iteration
Use a FOR loop when you know exactly how many times to repeat. It uses a counter variable that increments automatically.
15. Basic Array Algorithms Algorithms
Typical tasks include finding the Total, Average, or Maximum value in an array.
max β list[0]
FOR i β 1 TO len(list)-1
IF list[i] > max THEN
max β list[i]
ENDIF
NEXT i
16. Designing Complex Logic Problem Solving
Complex logic involves combining multiple constructsβlike using a selection (IF) statement inside an iteration (FOR) loop to filter data.
π― Final Knowledge Exam
Score: 0 / 20
π― Final Knowledge Exam
Find the correct answer to lock the question and score a point.
Score: 0 / 20