---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 22 Edition"
java_version: 22
chapter: "Chapter 16. Definite Assignment"
section: "16.2.12"
heading: "16.2.12. for Statements"
parent: "16.2. Definite Assignment and Statements"
source: https://docs.oracle.com/javase/specs/jls/se22/html/jls-16.html#jls-16.2.12
id: "16.2.12"
url: https://jvm.obfuscated.software/jls/se22/16.2.12.html
raw: https://jvm.obfuscated.software/jls/se22/16.2.12.md
---

# 16.2.12. `for` Statements

The rules herein cover the basic `for` statement ([§14.14.1](14.14.1.md)). Since the enhanced `for` statement ([§14.14.2](14.14.2.md)) is defined by translation to a basic `for` statement, no special rules need to be provided for it.

- V is [un]assigned after a `for` statement iff both of the following are true:

  - Either a condition expression is not present or V is [un]assigned after the condition expression when false.
  - V is [un]assigned before every `break` statement for which the `for` statement is the break target.

- V is [un]assigned before the initialization part of the `for` statement iff V is [un]assigned before the `for` statement.

- V is definitely assigned before the condition part of the `for` statement iff V is definitely assigned after the initialization part of the `for` statement.

- V is definitely unassigned before the condition part of the `for` statement iff both of the following are true:

  - V is definitely unassigned after the initialization part of the `for` statement.
  - Assuming V is definitely unassigned before the condition part of the `for` statement, V is definitely unassigned after the incrementation part of the `for` statement.

- V is [un]assigned before the contained statement iff either of the following is true:

  - A condition expression is present and V is [un]assigned after the condition expression when true.
  - No condition expression is present and V is [un]assigned before the condition part of the `for` statement.

- V is [un]assigned before the incrementation part of the `for` statement iff V is [un]assigned after the contained statement and V is [un]assigned before every `continue` statement for which the `for` statement is the continue target.

## 16.2.12.1. Initialization Part of `for` Statement

- If the initialization part of the `for` statement is a local variable declaration statement, the rules of [§16.2.4](16.2.4.md) apply.

- Otherwise, if the initialization part is empty, then V is [un]assigned after the initialization part iff V is [un]assigned before the initialization part.

- Otherwise, three rules apply:

  - V is [un]assigned after the initialization part iff V is [un]assigned after the last expression statement in the initialization part.
  - V is [un]assigned before the first expression statement in the initialization part iff V is [un]assigned before the initialization part.
  - V is [un]assigned before an expression statement S other than the first in the initialization part iff V is [un]assigned after the expression statement immediately preceding S.

## 16.2.12.2. Incrementation Part of `for` Statement

- If the incrementation part of the `for` statement is empty, then V is [un]assigned after the incrementation part iff V is [un]assigned before the incrementation part.

- Otherwise, three rules apply:

  - V is [un]assigned after the incrementation part iff V is [un]assigned after the last expression statement in the incrementation part.
  - V is [un]assigned before the first expression statement in the incrementation part iff V is [un]assigned before the incrementation part.
  - V is [un]assigned before an expression statement S other than the first in the incrementation part iff V is [un]assigned after the expression statement immediately preceding S.
