Page 137 - 만들면서 배우는 아두이노 드론
P. 137

6.5 제어문

여러 번 반복 처리해야 하는 경우 for 또는 while 제어문을 이용합니다. 일정 횟수만
큼 반복하려면 for 문으로 처리하며, while 문은 조건이 참인 경우만 명령문을 반복
합니다.

 void setup() {
    Serial.begin(9600);

    for(int i=1; i<=25; i++) {
       Serial.println(i);

    }
 }

 void loop() {
 }

      ? for 제어문은 초기값(i=1), 종료조건(i<=25), 증가분(i++) 을 설정해야 합니
            다.

      ? i++ 는 i = i + 1 과 동일합니다.

 const int speed = 9600; // 상수 변수 선언

 void setup() {
    Serial.begin(speed);

 }

 void loop() {
    int i = 0;
    while(i < 5) {
       i = i + 1;
       Serial.println(i);
       delay(1000);
    }

 }

                                                      136
   132   133   134   135   136   137   138   139   140   141   142