> For the complete documentation index, see [llms.txt](https://westsilver.gitbook.io/study-script/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://westsilver.gitbook.io/study-script/javascript/jacascript-start/undefined/untitled-2.md).

# 반복문

## 반복문(Loop Statement, iterate)

> 컴퓨터에게 반복적인 작업을 지시하는 방법

## 1.while문

```javascript
let i = 0;
while(조건){
    실행문;
    증감문;
}
```

```javascript
let i = 0; //초기화
while(i < 10){ //조건 선택식
    document.write('coding everybody'+i+'<br />'); //실행
    i++
}
```

### 1-1. 반복 조건

예시)

```javascript
let i = 0;
while(i < 10){
    document.write('coding everybody '+(i*2)+'<br />'); 
    //10 이하~ 2의 배수
    i++;
}
```

## 2. for문&#x20;

```javascript
for(초기화; 반복조건; 반복이 될 때마다 실행되는 코드){    
    반복해서 실행될 코드
}
```

```javascript
for(i = 0; i < 10; i++){    
    document.write('coding everybody'+i+'<br />');
}
```

## 3. 반복문의 제어

### 3-1. break

* 반복작업을 중간에 중단시키고 싶을 때 사용
* 반복문 안에서 break가 실행되면 반복문을 즉시 종료 시키게 됨

```javascript
for(var i = 0; i < 10; i++){
    if(i === 5) {
        break; //i ===5 라면 break 로 반복문을 빠져나감
    }
    document.write('coding everybody'+i+'<br />');
}

return

coding everybody 0
coding everybody 1
coding everybody 2
coding everybody 3
coding everybody 4
```

### 3-2. continue

조건까지 실행 즉시 중단하지만, 그 후의 반복은 지속되게 할 때 사용

```javascript
for(var i = 0; i < 10; i++){
    if(i === 5) {
        continue; //해당 조건에만 반복문 종료 
    //i =5 가 되었을 때 실행이 중단되었지만 반복문은 계속 실행

    }
    document.write('coding everybody'+i+'<br />');
}

//coding everybody 0
//coding everybody 1
//coding everybody 2
//coding everybody 3
//coding everybody 4
//coding everybody 6
//coding everybody 7
//coding everybody 8
//coding everybody 9 
```

## 4. 반복문의 중첩

```javascript
for(let i = 0; i < 10; i++){ 
    for(let j = 0; j < 10; j++){
        document.write(String(i)+String(j)+'<br />'); 
        //String은 숫자인 i와 j의 데이터 타입을 문자로 변환하는 명령
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://westsilver.gitbook.io/study-script/javascript/jacascript-start/undefined/untitled-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
