Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 1006 Bytes

File metadata and controls

65 lines (45 loc) · 1006 Bytes
title categories subCategories
break
Structure
제어 구조

break

설명

breakfor, while 또는 do…​while loop 로부터 빠져나가 정상 루프를 건너 뛰는데 쓰인다. switch case 문으로부터 빠져나갈 때도 쓰인다.

예제 코드

아래 코드에서, 센서값이 임계값을 넘을 때 제어는 for 를 빠져나간다.

int threshold = 40;
for (int x = 0; x < 255; x ++) {
  analogWrite(PWMpin, x);
  sens = analogRead(sensorPin);
  if (sens > threshold) { // bail out on sensor detect
    x = 0;
    break;
  }
  delay(50);
}

더보기