Files
2nd/10_Wiki/Dev/Topic_C/C_Do_While_Loop.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

3.9 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
c-do-while-loop C Do/While Loop Programming_Language draft conceptual
do while
at-least-once loop
scanf input validation loop
C do-while 반복문
B 0.86 2026-07-04 2026-07-04
c
programming-language
w3schools
loops
do-while
https://www.w3schools.com/c/c_do_while_loop.php

C Do/While Loop

🎯 한 줄 통찰 (One-line insight)

The core difference from a regular while loop isn't cosmetic syntax — it's WHEN the condition is checked: do/while runs the body FIRST and evaluates the condition only AFTER, guaranteeing at least one execution even if the condition is false from the very start (int i = 10; do {...} while (i < 5); still runs once), which is exactly the opposite of the plain while loop's zero-iteration behavior shown in the previous chapter. [S1]

🧠 핵심 개념 (Core concepts)

  • do { ... } while (condition); — executes the block ONCE unconditionally, then checks the condition to decide whether to repeat. [S1]
  • Guaranteed first execution — unlike while, the body runs at least once even if the condition is false immediately. [S1]
  • Use case: "at least once" behavior — ideal for scenarios like showing a message or prompting for user input, where the action must happen before any condition can even be evaluated. [S1]
  • Input-validation pattern — repeatedly prompting via scanf() until the user provides a value that fails the loop condition (e.g. entering 0 or negative to stop). [S1]

📖 세부 내용 (Details)

  • Standard case (condition true at start): int i = 0; do { printf("%d\n", i); i++; } while (i < 5);. [S1]
  • Guaranteed-once case (condition false at start): int i = 10; do { printf("i is %d\n", i); i++; } while (i < 5); — still prints once despite i < 5 being false immediately. [S1]
  • Practical input-validation loop: int number; do { printf("Enter a positive number: "); scanf("%d", &number); } while (number > 0); — keeps prompting until 0 or a negative number is entered. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • do/while은 조건과 무관하게 최소 1회 실행: 일반 while 루프는 조건이 처음부터 거짓이면 아예 실행되지 않지만, do/while은 조건이 거짓이어도 반드시 한 번은 실행된다는 점이 직접 대비되어 강조됨. [S1]

🛠️ 적용 사례 (Applied in summary)

사용자로부터 양수를 입력받되 0이나 음수가 입력될 때까지 반복해서 물어보는 입력 검증 루프가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

💻 코드 패턴 (Code patterns)

An input-validation loop that must prompt at least once before checking the exit condition (C):

int number;
do {
  printf("Enter a positive number: ");
  scanf("%d", &number);
} while (number > 0);

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.86
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C Do/While Loop" page (Astra wiki-curation, P-Reinforce v3.1 format).