• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 3 pages
Summary

Summary Programming Fundamentals: Variables, Control Flow, Functions and Debugging

Document preview thumbnail
Preview 1 out of 3 pages

Study notes for a first-year Programming Fundamentals module, organised the way a practical exam marks an answer. Section 1 covers variables, primitive and reference types, static versus dynamic typing, declaration and initialisation, expressions, operator precedence and integer division. Section 2 covers selection with if/else and switch, short-circuit evaluation, for and while loops, nested iteration, break and continue, and the loop invariant. Section 3 covers functions, parameters, return values, decomposition, pass by value versus reference, and recursion with its base case. Section 4 covers debugging as reproduce-locate-fix, print and breakpoint methods, unit, integration and acceptance tests, boundary and invalid-input cases, and black-box versus white-box testing. Includes a construct comparison table, four practice questions with marking checkpoints, a glossary and a 40-minute revision plan.

Content preview

Programming Fundamentals: Variables, Control Flow,
Functions and Debugging
How a beginner program is built, tested and repaired - in the order a marker looks for
Computer Science | Undergraduate (Level 4) | December 2026


WHAT IS INSIDE

1. Variables, types and expressions
2. Control flow: selection and iteration
3. Functions, parameters and decomposition
4. Testing, debugging and program quality
Exam question patterns
Glossary of exam-ready definitions

1. Variables, types and expressions
A variable is a named location holding a value of a particular type; what the type allows determines what the
program can do without crashing. Primitive types - integer, floating point, boolean, character - are stored
directly, while reference types such as strings and objects hold the location of data. Static typing checks
types before the program runs and catches mistakes early; dynamic typing checks at runtime and trades that
safety for flexibility, which is why the same one-line error becomes a compile error in one language and a
crash in another.
Declaring, initialising and assigning are three separate acts and exam questions test them separately: an
uninitialised variable holds whatever the language's default rule gives it (not necessarily zero), a reassignment
of an incompatible type is a type error in a static language and a silent conversion or runtime failure in a
dynamic one. Expressions combine literals, variables and operators; operator precedence and integer
division are the two sources of most wrong answers, since 7/2 is 3 in integer arithmetic and 3.5 in floating
point.
• Scope - a variable exists only inside the block in which it is declared; using it outside is the most common
beginner error.
• Immutability - a constant cannot be reassigned; declare it so when the value must not change.
• Casting - widening conversions are safe, narrowing ones truncate or throw; state which in your answer.
• Naming - a descriptive identifier is marked in a trace question, because the reader must follow the state.

2. Control flow: selection and iteration
Selection chooses a path: if/else chains test conditions in order and stop at the first true branch, while a
switch or match compares one value against constant cases. The condition must be a boolean expression, and
the three classic bugs are an assignment written where a comparison was meant, an off-by-one boundary, and
a missing else that leaves a path unhandled. Short-circuit evaluation means the second operand of and/or is
not evaluated when the result is already decided - a detail that exam questions use to explain why a null check
must come first.
Iteration repeats work: a for loop is appropriate when the number of repetitions is known, a while loop when
it depends on a condition, and a do-while when the body must run at least once. Nested loops multiply their
counts, which is the source of the complexity result most students state without justification. break and
continue change the loop's control, and an infinite loop is diagnosed by showing which variable the loop
depends on never changes.


Programming Fundamentals: Variables, Control Flow, Functions Page 1 of 3

Document information

Study
Unknown
Uploaded on
December 2, 2026
Number of pages
3
Written in
2026/2027
Type
Summary
$7.98

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
225
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions