---
title: "AP CSA Practice 4: Document Code and Computing Systems"
description: "Learn AP Computer Science A Practice 4: describe code behavior and the initial conditions needed for a code segment to work as intended."
canonical: "https://fiveable.me/ap-comp-sci-a/computational-thinking-practices/practice-4-document-code-and-computing-systems/study-guide/B3iUyDraGGQaemlAs00X"
type: "study-guide"
subject: "AP Computer Science A"
unit: "**Computational Thinking Practices"
lastUpdated: "2026-06-17"
---

# AP CSA Practice 4: Document Code and Computing Systems

## Summary

Learn AP Computer Science A Practice 4: describe code behavior and the initial conditions needed for a code segment to work as intended.

## Guide

## Overview

[AP Computer Science A](/ap-comp-sci-a "fv-autolink") Practice 4: Document Code and Computing Systems is the skill of describing what a program does and the conditions that produce a specific result. You read a code segment, then explain its overall behavior in plain language or identify what inputs and starting values it needs to work correctly. This practice is about understanding and communicating the purpose of code, not just [tracing](/ap-comp-sci-a/key-terms/tracing "fv-autolink") a single output.

Practice 4 shows up only on the multiple-choice section. It carries roughly 10 to 15 percent of the multiple-choice weighting, so it is worth real points but smaller than Practice 2 (Develop Code) and Practice 3 (Analyze Code).

## What Practice 4 - Document Code and Computing Systems Means

This practice has two subskills, both tested on the MCQ section and neither on the FRQ section.

- **4.A: Describe the behavior of a code segment or program.** You summarize what the code accomplishes as a whole. Instead of "what prints on this exact [input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment "fv-autolink")," you answer "what does this code do for any valid input."
- **4.B: Describe the initial conditions that must be met for a code segment to work as intended or described.** You identify the starting values, inputs, or [array](/ap-comp-sci-a/unit-4/array-creation-and-access/study-guide/umTe6NA38OqZOhMZjFWi "fv-autolink") contents that have to be true so the code produces the described result.

The connecting idea is documentation. A good description and a clear set of preconditions are how programmers communicate intent.

## What This Practice Requires

You need to do two related things.

1. **Generalize behavior.** Read past one specific run and state the rule the code follows. For example, recognizing that a [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink") multiplies together only the positive values in a [2D array](/ap-comp-sci-a/unit-4/2d-arrays/study-guide/5WDx6ZFeWhx2aVuiZI6R "fv-autolink").
2. **Work backward from a goal.** Given a target result, find the inputs or initializations that make it happen. For example, choosing the array contents that make a column sum equal 3.

Both require careful reading of loops, conditionals, [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") calls, and array indexing without losing the big picture.

## Skills You Need for This Practice

- Trace loops and conditionals well enough to see the [pattern](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z "fv-autolink"), then describe it in one sentence.
- Recognize what a condition filters or selects, like `if (value > 0)` keeping only positive numbers.
- Understand array and 2D array indexing, including which [index](/ap-comp-sci-a/key-terms/index "fv-autolink") is the row and which is the column.
- Connect a described outcome back to required inputs, such as nonempty arrays or specific ranges.
- Read method headers and preconditions, like `/** Precondition: ranges contains at least one element. */`.

## How It Shows Up on the AP Exam

- **Only multiple-choice.** Practice 4 is not assessed on the four free-response questions.
- **Behavior questions (4.A)** often ask "which of the following best describes the behavior of the code segment?" The answer choices are full-sentence descriptions, and one captures what the code does for all valid inputs.
- **Condition questions (4.B)** often ask which [initialization](/ap-comp-sci-a/key-terms/initialization "fv-autolink") or input "will cause the code segment to print" a specific value or "works as intended." You pick the starting data that produces the stated result.
- Distractors usually describe a closely related but wrong behavior, such as "product of all negative elements" instead of positive, or an initialization that produces a different sum.

## Examples Across the Course

These pull from different units so you can see Practice 4 across content areas.

**[Unit 4](/ap-comp-sci-a/unit-4 "fv-autolink"), 2D arrays (4.A, behavior).**
```java
int[][] arr = {{10, -7, 19, 14},
               {-3, -2, -6, 11},
               {-9, 12, 10, -1}};
int ans = 1;
for (int[] row : arr)
    for (int value : row)
        if (value > 0)
            ans = ans * value;
System.out.println(ans);
```
The best description: it prints the product of all the positive elements in `arr`. The `if (value > 0)` filter and the multiplicative start `ans = 1` are the keys.

**Unit 4, 2D arrays (4.B, conditions).**
```java
int[][] arr2D = /* missing initialization */;
int sum = 0;
for (int j = 0; j < arr2D.length; j++)
    sum += arr2D[j][2];
System.out.println(sum);
```
To print 3, the initialization must put values in [column index](/ap-comp-sci-a/key-terms/column-index "fv-autolink") 2 (the third column) that add up to 3. A three-row array with a 1 in column 2 of each row works.

**[Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink"), loops (4.A, behavior).** A `while` loop containing a `for` loop that runs a fixed number of times each pass executes its inner statement (outer count) times (inner count). Describing this as "repeats the inner action a set number of times for each outer pass" is a behavior summary.

**Unit 4, arrays with preconditions (4.B, conditions).** A method labeled `/** Precondition: ranges contains at least one element. */` only works as described when that [precondition](/ap-comp-sci-a/unit-1/documentation-with-comments/study-guide/scrDad77j4e5vwrFab5J "fv-autolink") holds. Recognizing that an empty array would break a max-finding method is condition reasoning.

**Unit 1 and Unit 3, [objects](/ap-comp-sci-a/key-terms/object "fv-autolink") (4.B, conditions).** A constructor like `Date(String m, int d)` requires arguments matching those types in that order. Describing the conditions to create a valid object means knowing the constructor's [parameter list](/ap-comp-sci-a/key-terms/parameter-list "fv-autolink") must be satisfied.

## How to Practice Practice 4 - Document Code and Computing Systems

Practical advice, not official rules:

- After tracing any code, force yourself to write one sentence: "This code does ___ for any valid input." That trains 4.A directly.
- For 4.B, start from the desired output and ask "what would have to be true at the start?" Test your answer by plugging it in.
- Pay attention to [accumulator](/ap-comp-sci-a/key-terms/accumulator "fv-autolink") starting values. `sum = 0` and `product = 1` change what counts as correct behavior.
- Note index choices in 2D arrays. `arr2D[j][2]` always touches column 2, so conditions live in that column.
- Read preconditions in method comments and treat them as required initial conditions.

## Common Mistakes

- **Describing one run instead of the rule.** A 4.A answer should hold for all valid inputs, not just the example values shown.
- **Confusing related [behaviors](/ap-comp-sci-a/key-terms/behavior "fv-autolink").** Mixing up positive vs negative, sum vs product, or rows vs columns leads straight to a distractor.
- **Ignoring the starting value.** Forgetting that `ans = 1` makes the loop a product, not a sum.
- **Mixing up row and column indexing** in 2D array condition questions.
- **Overlooking preconditions.** Choosing an input that violates a stated precondition, like passing an empty array, breaks "works as intended."

## Quick Review

- Practice 4 has two subskills: **4.A** describe behavior, **4.B** describe required initial conditions.
- Both are **MCQ only**, about **10 to 15 percent** of the multiple-choice section.
- **4.A** asks what the code does in general; pick the description true for all valid inputs.
- **4.B** asks what inputs or initializations make a described result happen; work backward from the goal.
- Watch accumulator start values, condition filters, array indexing, and stated preconditions.
