Common Mistakes in Programming Fundamentals

48 common pitfalls across 12 concepts, including 12 recurring stuck points

These are the pitfalls students hit across all 12 programming fundamentals concepts, from Assignment, Integer and String onward. Each entry names the concept it comes from, so you can tell a slip from a genuine gap and go straight to the explanation.

1
Assignment
Stuck Point

= means 'assign,' not 'equals.' Many languages use == for equality comparison.

2
Assignment
Mistake

Confusing the assignment operator (=) with the equality test (==), especially in conditions

3
Assignment
Mistake

Reading x = x + 1 as a mathematical equation instead of an update instruction

4
Assignment
Mistake

Forgetting that the right side is evaluated first, so all variables on the right use their old values

5
Integer
Stuck Point

Integer division truncates in many languages: 7 / 2 gives 3, not 3.5. This catches many beginners by surprise.

6
Integer
Mistake

Expecting 7 / 2 to give 3.5 when using integer division, which truncates to 3 in many languages

7
Integer
Mistake

Causing integer overflow by exceeding the maximum value a fixed-width integer can hold

8
Integer
Mistake

Using integers for values that need decimal precision, like currency calculations

9
String
Stuck Point

'123' is a string, not a number. You can't do math with it until you convert it: int('123') gives the number 123.

10
String
Mistake

Using + between a string and a number without converting, causing a TypeError in Python (Java and JavaScript instead turn the number into text and join them)

11
String
Mistake

Forgetting that string indices start at 0, so the first character is s[0] not s[1]

12
String
Mistake

Assuming strings are mutable—in many languages (Python, Java), strings cannot be changed in place; operations create new strings

13
Boolean
Stuck Point

0, empty string, None/null, and empty lists are often 'falsy' — they act like False in conditions even though they're not boolean.

14
Boolean
Mistake

Comparing a boolean to True explicitly (if x == True) instead of using it directly (if x)

15
Boolean
Mistake

Not understanding truthy/falsy values—0, empty string, None, and empty list evaluate as False in conditions

16
Boolean
Mistake

Using assignment (=) instead of equality (==) in a boolean expression, which changes the variable instead of testing it

17
Return Values
Stuck Point

Print and return are different. Print displays a value; return sends it back to the calling code for further use.

18

Using print instead of return, then wondering why the calling code receives None/undefined

19

Forgetting to capture the return value in a variable, so the result is computed but immediately lost

20

Placing code after a return statement, which never executes because return exits the function immediately

21
Scope
Stuck Point

Modifying a global variable inside a function usually requires a special keyword (global in Python). Without it, you create a new local variable.

22
Scope
Mistake

Accidentally creating a new local variable instead of modifying the intended global variable

23
Scope
Mistake

Trying to access a local variable outside the function where it was defined, causing a NameError

24
Scope
Mistake

Over-relying on global variables instead of passing data through parameters, making code hard to debug and test

25

Deep nesting makes code hard to read. Consider using elif/else-if chains or combining conditions with AND/OR instead.

26

Nesting too deeply (more than 3 levels) when the logic could be simplified with combined boolean conditions

27

Losing track of which else belongs to which if, especially without proper indentation

28

Duplicating code across branches instead of restructuring to eliminate redundancy

29
While Loop
Stuck Point

Forgetting to update the loop variable creates an infinite loop. Always make sure the condition will eventually become false.

30
While Loop
Mistake

Forgetting to update the loop variable inside the body, causing an infinite loop

31
While Loop
Mistake

Using the wrong comparison operator in the condition (< vs <=), causing off-by-one errors

32
While Loop
Mistake

Not initializing the loop variable before the while statement, causing an error or wrong behavior on the first check

33
For Loop
Stuck Point

range(5) gives 0 to 4, not 1 to 5. Off-by-one errors are the most common for-loop bug.

34
For Loop
Mistake

Off-by-one errors: range(5) gives [0,1,2,3,4], not [1,2,3,4,5]

35
For Loop
Mistake

Modifying the collection being iterated over during the loop, causing skipped elements or errors

36
For Loop
Mistake

Using a for loop when the number of iterations is unknown—a while loop is more appropriate in that case

37
Event Handler
Stuck Point

An event handler is registered (set up) once but can fire many times. Setting it up doesn't run it immediately.

38

Calling the function immediately instead of passing it as a reference (button.onClick(myHandler()) runs it now; button.onClick(myHandler) registers it)

39

Registering a handler more than once (for example, setup code that runs twice and adds a new anonymous function each time), causing it to fire once per registration

40

Writing slow event handlers that block the main thread and make the interface freeze

41
File Operations
Stuck Point

Always close files when done (or use with-statements). Unclosed files can lose data or lock the file from other programs.

42

Forgetting to close the file after reading or writing, risking data loss or file locks

43

Opening a file in write mode ('w') when you meant to append ('a'), accidentally erasing all existing content

44

Not handling the case where the file does not exist, causing the program to crash with a FileNotFoundError

45
Function
Stuck Point

Defining a function doesn't run it — you must call it. Parameters (defined) differ from arguments (passed in).

46
Function
Mistake

Defining a function but never calling it, then wondering why nothing happens

47
Function
Mistake

Writing functions that are too long and do too many things, making them hard to test and reuse

48
Function
Mistake

Confusing parameters (placeholders in the definition) with arguments (actual values passed at the call site)