docs(10_Wiki): W3Schools 위키화 — HTML/CSS/JavaScript(core)

W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더).
- Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외)
- Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체)
- Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속)
각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-23 19:21:18 +09:00
parent 8957890d13
commit 9609c04755
379 changed files with 54618 additions and 6 deletions
@@ -0,0 +1,147 @@
---
id: javascript-for-loop
title: "JavaScript For Loop"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["for loop", "JS for loop", "for statement", "loop expressions", "for loop scope"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.89
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["javascript", "js", "web", "frontend", "w3schools", "for-loop", "loops", "iteration"]
raw_sources: ["https://www.w3schools.com/js/js_loop_for.asp"]
applied_in: []
github_commit: ""
---
# [[JavaScript For Loop]]
## 🎯 한 줄 통찰 (One-line insight)
The `for` statement creates a loop with three optional expressions — initialize, test, update — letting a code block run a controlled number of times. [S1]
## 🧠 핵심 개념 (Core concepts)
- **Three optional expressions** — the `for` statement creates a loop with three optional expressions. [S1]
- **exp1 — initializer** — sets a variable before the loop starts (`let i = 0`), and can be omitted if initialization happens beforehand. [S1]
- **exp2 — condition** — defines the condition for the loop to run; it is optional, but if omitted you must `break` inside the loop or it runs forever. [S1]
- **exp3 — update** — increases a value (`i++`) after the code block executes; it is optional and can do other operations. [S1]
- **Loop scope matters** — `let` scopes the counter to the loop; `var` redeclares the outer variable. [S1]
## 🧩 추출된 패턴 (Extracted patterns)
- **Index-driven array traversal** — cache `cars.length` once, then iterate `i` from 0 to that length. [S1]
- **Omit-and-supply elsewhere** — any of the three expressions can be moved out of the `for(...)` header (initialize before, update inside the body). [S1]
- **Prefer `let` for the counter** — keeps `i` private to the loop. [S1]
## 📖 세부 내용 (Details)
**The `for` statement** [S1]
The `for` statement creates a loop with 3 optional expressions, allowing the code block to execute multiple times.
- **exp1** sets a variable before the loop starts (`let i = 0`).
- **exp2** defines the condition for the loop to run (`i` must be less than 5).
- **exp3** increases a value (`i++`) after the code block has been executed.
The first expression can be omitted if initialization occurs before the loop. The second expression is optional but requires a `break` statement inside the loop to prevent infinite execution. The third expression is optional and can perform various operations like negative increment or custom calculations.
**Basic for loop** [S1]
```javascript
for (let i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
```
**Iterating through an array** [S1]
```javascript
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let len = cars.length;
let text = "";
for (let i = 0; i < len; i++) {
text += cars[i];
}
```
**Omitting exp1** [S1]
```javascript
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let len = cars.length;
let i = 2;
let text = "";
for (; i < len; i++) {
text += cars[i] + "<br>";
}
```
**Omitting exp3** [S1]
```javascript
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let len = cars.length;
let i = 0;
let text = "";
for (; i < len; ) {
text += cars[i] + "<br>";
i++;
}
```
**Loop scope** [S1]
Using `var` in a loop, the loop variable redeclares the outer variable:
```javascript
var i = 5;
for (var i = 0; i < 10; i++) {
// some code
}
// Here i is 10
```
Using `let` in a loop, the variable is scoped only within the loop. When `let` is used to declare the `i` variable, the `i` variable will only be visible within the loop:
```javascript
let i = 5;
for (let i = 0; i < 10; i++) {
// some code
}
// Here i is 5
```
## 🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — counting 04, traversing a `cars` array (with `len` cached), and demonstrating exp1/exp3 omission and `let`/`var` scoping. No external project/commit applications found in the source.
## 💻 코드 패턴 (Code patterns)
Standard counted loop:
```javascript
for (let i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
```
Array traversal with cached length:
```javascript
const cars = ["BMW", "Volvo", "Saab", "Ford"];
let len = cars.length;
for (let i = 0; i < len; i++) {
text += cars[i];
}
```
## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
- **`let` vs `var` for the counter** — `let` keeps `i` visible only inside the loop (`i` is 5 afterward in the example); `var` leaks/redeclares it to the outer scope (`i` is 10 afterward). Prefer `let`. [S1]
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
No contradictions found in the source.
## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.89
- **중복 검사 결과:** 신규 생성 (New discovery)
## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[JavaScript Tutorial]]
- **관련 개념:** [[JavaScript Loops]], [[JavaScript While Loop]], [[JavaScript Break]], [[JavaScript For In]]
- **참조 맥락:** The primary counted-iteration construct; detailed expansion of the `for` loop introduced in [[JavaScript Loops]].
## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript For Loop — https://www.w3schools.com/js/js_loop_for.asp
## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript For Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).