Loops, functions, modularization and scope
Programming fundamentals turn algorithms into reliable executable procedures. Scope, data types, debugging and exceptions all affect correctness. Programming constructs control the order, branching and repetition of instructions and support modular solutions.
What you need to be able to do
- ConstructPrograms that can extract and manipulate substrings
- ConstructPrograms that utilize looping structures to perform repeated actions
- ConstructFunctions and modularization
Rapid Recall Deck
Say the answer aloud before flipping. Mark secure knowledge quickly and spend time on the gaps.
- What is a substring?: A substring is a contiguous sequence of characters taken from within a larger string.
- What kinds of operations can be performed when manipulating strings and substrings?: Identifying and extracting substrings, then altering, concatenating, or replacing text as required.
- What is the difference between a counted loop and a conditional loop?: A counted loop repeats a known or controlled number of times; a conditional loop repeats while or until a condition determines that it should stop.
- How can Boolean and relational expressions control a loop?: They determine whether the loop continues, stops, or whether conditional code inside the loop executes.
- What is the purpose of a function?: A function packages a reusable block of code that can receive inputs and perform a defined task.
- Why is modularization useful?: It divides a program into well-structured, reusable, maintainable parts that are easier to test and reason about.
Core knowledge and application
Programs that can extract and manipulate substrings
Programming fundamentals turn algorithms into reliable executable procedures. Scope, data types, debugging and exceptions all affect correctness.
Explain it without notes
Construct: Programs that can extract and manipulate substrings in the context of a student-record processing program.
- Writing of programs that accurately identify and extract substrings from given strings, demonstrating the ability to perform various manipulations, such as altering, concatenating or replacing
Programs that utilize looping structures to perform repeated actions
Programming constructs control the order, branching and repetition of instructions and support modular solutions.
Explain it without notes
Construct: Programs that utilize looping structures to perform repeated actions in the context of a program that validates and processes course choices.
- Types of loops, including counted loops and conditional loops, and appropriate use of each type
- Conditional statements within loops, using Boolean and/or relational operators to govern the loop’s execution
Core knowledge and application
Functions and modularization
Programming constructs control the order, branching and repetition of instructions and support modular solutions.
Explain it without notes
Construct: Functions and modularization in the context of a program that validates and processes course choices.
- Functions to define reusable blocks of code with different inputs
- Modularization to create well-structured, reusable and maintainable code
- The principles of scope (local versus global)
- The benefits of code modularization, applying this concept to various programming scenarios
Programming checkpoint
def count_passes(scores):
total = 0
for score in scores:
if score >= 50:
total += 1
return totalstatic int countPasses(int[] scores) {
int total = 0;
for (int score : scores) {
if (score >= 50) total++;
}
return total;
}Modify it
Change one condition, input or operation so the program solves a slightly different problem. Predict the effect before editing.
Substring extraction and manipulation
Python
course = "ComputerScience"
prefix = course[0:8]
updated = course.replace("Science", "Systems")
message = prefix + " / " + updated
print(message)Java
String course = "ComputerScience";
String prefix = course.substring(0, 8);
String updated = course.replace("Science", "Systems");
String message = prefix + " / " + updated;
System.out.println(message);Science instead.Why modularize?
Put repeated string processing inside a function/method with inputs and a return value. This reduces duplicated code, makes testing easier and keeps local variables scoped to the task.
Transfer to a new scenario
- Writing of programs that accurately identify and extract substrings from given strings, demonstrating the ability to perform various manipulations, such as altering, concatenating or replacing
- Types of loops, including counted loops and conditional loops, and appropriate use of each type
- Conditional statements within loops, using Boolean and/or relational operators to govern the loop’s execution
- Functions to define reusable blocks of code with different inputs
- Modularization to create well-structured, reusable and maintainable code
Paper 2 practice
- Construct: Programs that can extract and manipulate substrings in the context of a student-record processing program.
- Construct: Programs that utilize looping structures to perform repeated actions in the context of a student-record processing program.
- Construct: Functions and modularization in the context of a student-record processing program.
Finish the learning cycle
IA — main task
Refine Criteria A/B/C. Use today’s lesson to make the problem specification, decomposition, algorithms or testing plan more precise where relevant.
Syllabus — 10–15 min
Repeat the recall deck and complete the lesson response prompt without model support.