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>
6.1 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| javascript-loops | JavaScript Loops | Frontend | draft | conceptual |
|
B | 0.88 | 2026-06-23 | 2026-06-23 |
|
|
JavaScript Loops
🎯 한 줄 통찰 (One-line insight)
Loops let you run the same block of code many times, each time with a different value — replacing long repetitive sequences with a compact iteration. [S1]
🧠 핵심 개념 (Core concepts)
- Loops repeat a block of code — they execute a code block multiple times, often with a different value each pass. [S1]
forloop — uses three expressions: an initializer, a condition, and an update run after each iteration. [S1]whileloop — runs as long as a specified condition is true. [S1]do/whileloop — a variant that runs the block at least once before checking the condition. [S1]- Loop scope — variables declared with
letinside a loop are visible only within the loop, unlikevar. [S1] - Infinite-loop hazard — forgetting to update the condition variable means the loop never ends and crashes the browser. [S1]
🧩 추출된 패턴 (Extracted patterns)
- Replace repetition with iteration — instead of writing the same statement for each array index, loop over
cars.length. [S1] - Index accumulation — append each iteration's value into a result string (
text += ...). [S1] - Always advance the condition variable — increment (e.g.
i++) so the condition eventually becomes false. [S1]
📖 세부 내용 (Details)
Why loops [S1] Loops are handy if you want to run the same code over and over again, each time with a different value. Instead of writing the same statement many times:
text += cars[0] + "<br>";
text += cars[1] + "<br>";
text += cars[2] + "<br>";
text += cars[3] + "<br>";
text += cars[4] + "<br>";
text += cars[5] + "<br>";
You can write:
for (let i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
The for loop [S1]
The for loop has the syntax for (expr1; expr2; expr3) { // code block to be executed }.
for (let i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
Loop scope — var vs let [S1]
Using var in a loop, the loop variable redeclares the outer variable:
let i = 5;
for (i = 0; i < 10; i++) {
// some code
}
// Here i is 10
Using let in a loop, the loop variable is scoped only to the loop:
let i = 5;
for (let i = 0; i < 10; i++) {
// some code
}
// Here i is 5
The while loop [S1]
The while loop has the syntax while (condition) { // code block to be executed }.
while (i < 10) {
text += "The number is " + i;
i++;
}
Note: If you forget to increase the variable used in the condition, the loop will never end. This will crash your browser.
The do/while loop [S1]
The do/while loop has the syntax do { // code block to be executed } while (condition);.
do {
text += "The number is " + i;
i++;
}
while (i < 10);
Note: The do while runs at least once, even if the condition is false from the start.
Different kinds of loops [S1]
JavaScript supports the for loop (loops through a block of code a number of times), the for/in loop (loops through the properties of an object), the for/of loop (loops through the values of an iterable object), the while loop (loops through a block of code while a condition is true), and the do/while loop (also loops while a condition is true).
🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — replacing repeated text += cars[n] statements with a for loop over cars.length, and accumulating numbers in for/while/do-while loops. No external project/commit applications found in the source.
💻 코드 패턴 (Code patterns)
Iterate an array:
for (let i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
While loop with advancing counter:
while (i < 10) {
text += "The number is " + i;
i++;
}
Do-while (runs at least once):
do {
text += "The number is " + i;
i++;
}
while (i < 10);
⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
forvswhile— useforwhen the number of iterations / the counter is known up front (init, condition, update in one place); usewhilewhen looping purely on a condition. [S1]whilevsdo/while— usedo/whilewhen the block must run at least once even if the condition is initially false. [S1]letvsvarfor the loop variable —letkeeps the counter scoped to the loop;varleaks it to the surrounding scope. [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.88
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: JavaScript Tutorial
- 관련 개념: JavaScript For Loop, JavaScript While Loop, JavaScript Break, JavaScript Booleans
- 참조 맥락: The overview entry point for all iteration constructs; specific loop types are detailed in their own pages.
📚 출처 (Sources)
- [S1] W3Schools — JavaScript Loops — https://www.w3schools.com/js/js_loops.asp
📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Loops" page (Astra wiki-curation, P-Reinforce v3.1 format).