Find the bug. Then see why it breaks.

Paste your code. Learnex pinpoints the faulty line, shows a failing test case and walks through execution step by step, so you can see what the program is really doing.

How to debug your code with the Learnex Code Lab

  1. 1

    Paste your code and pick the language

    Python, JavaScript or TypeScript, Java, C++, Go and Rust are supported.

  2. 2

    Run Find My Bug

    Learnex pinpoints the faulty line, names the type of defect and gives a failing test case: input, expected output and actual output.

  3. 3

    Trace the execution

    Step through the algorithm on a concrete input and watch variables and the call stack change. At key branches you are asked to predict what happens next.

  4. 4

    Practise the fix

    Try a Parsons-style challenge: a function skeleton with the key logic missing, checked against edge cases.

Built to teach debugging, not just patch your code

Exact-line bug finder

Off-by-one errors, unbounded recursion, modifying a list while iterating, null or undefined dereferences, integer-division traps and reference-versus-value mutation.

A failing test case every time

Input, expected output and actual output, so you can see the bug rather than take it on trust.

Execution trace with a live memory table

Follow variables like low, high and mid, plus call-stack frames, one step at a time.

Predict-the-next-step prompts

At critical branches the lab asks what happens next, training the mental model you need in exams and interviews.

Parsons-style scaffolding

Fill in the missing core logic of a clean skeleton and get a pass/fail matrix on edge cases.

Big-O and a rule of thumb

Time and space complexity for the code, plus a short exam-ready rule to avoid the same bug again.

Example: an off-by-one in binary search

This binary search looks fine but crashes on some inputs.

Student code

def binary_search(arr, target):
low, high = 0, len(arr) # <- faulty line: should be len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1

Failing test case

Input: arr = [1, 3], target = 5
Expected: -1
Actual: IndexError: list index out of range

Why it breaks

high starts one past the last valid index. With target 5, low becomes 2 and mid becomes 2, so arr[2] reads outside the list.

Fix and complexity

low, high = 0, len(arr) - 1 # Time O(log n), Space O(1)

Key Takeaway

Defect type: off-by-one boundary error. Rule of thumb: when the loop condition is low <= high, high must be the last valid index.

Frequently asked questions

How do I debug code step by step?

Reproduce the failure with a concrete input, then trace the variable values line by line until you find the first point where the actual state differs from what you expected. The Learnex Code Lab guides you through both parts: it pinpoints the faulty line, shows a failing test case and walks execution with a live memory table.

Which programming languages does the Code Lab support?

Python, JavaScript and TypeScript, Java, C++, Go and Rust are supported for the Find My Bug diagnostic.

Does the Code Lab run my code?

The trace is an AI-guided walkthrough built for learning. It is not a replacement for your compiler or debugger, so use it to understand what is going on, then confirm the behaviour in your own environment before you submit.

How is this different from asking a chatbot to fix my code?

A fixer hands back rewritten code. The Code Lab is built to teach: it locates the line, names the defect type, proves the problem with a failing case, and then asks you to predict and rewrite the logic yourself.

What is a Parsons problem?

A Parsons problem gives you a working structure with the key logic left out, so you practise writing the part that matters. In the Code Lab your answer is checked against edge cases and you see which tests pass and fail.

Is it okay to use this for assignments?

The Code Lab is designed to help you understand your own mistakes, not to write assignments for you. Check your course's rules on AI assistance before using any tool on graded work.

Related tools & labs

Master the reasoning behind every answer

Practice the step-by-step logic exams actually test with Learnex Labs.

START FREE →

Last updated 2026-11-04