Menu
Coddy logo textTech

논리 OR

Coddy Dart 여정의 기초 섹션에 포함된 레슨 — 94개 중 24번째.

논리 OR 연산자 (||)는 적어도 하나의 표현식이 true일 때 true를 반환하며, 둘 다 false일 때만 false를 반환합니다.

void main() {
  bool hasCreditCard = false;
  bool hasDebitCard = true;
  
  bool canPayOnline = hasCreditCard || hasDebitCard;
  
  print('Can this person pay online? $canPayOnline');
}

출력: Can this person pay online? true

void main() {
  int age = 16;
  bool hasParentalConsent = true;
  
  bool canWatchMovie = (age >= 18) || (age >= 13 && hasParentalConsent);
  
  print('Can watch the movie? $canWatchMovie');
}
challenge icon

챌린지

초급

논리 OR (||) 연산자를 사용하여 게임 자격 확인기를 만드세요:

  1. 값 15로 정수 변수 age를 선언하세요
  2. 값 true로 불리언 변수 hasParentalConsent를 선언하세요
  3. 다음 중 하나를 확인하는 불리언 변수 canPlayGame를 선언하세요:
    • 사람이 18세 이상 (age >= 18)인 경우, OR
    • 사람이 부모 동의를 받은 경우 (hasParentalConsent가 true인 경우)
  4. 이 정확한 형식으로 결과를 출력하세요:
Age: 15
Has parental consent: true
Can play game: true

그 다음 hasParentalConsent를 false로 변경하고 동일한 형식으로 업데이트된 결과를 출력하세요.

치트 시트

논리 OR 연산자 (||)는 적어도 하나의 표현식이 true일 때 true를 반환하고, 둘 다 false일 때만 false를 반환합니다.

bool canPayOnline = hasCreditCard || hasDebitCard;

OR을 다른 논리 연산자와 결합할 수 있습니다:

bool canWatchMovie = (age >= 18) || (age >= 13 && hasParentalConsent);

직접 해보기

void main() {
  // 여기에 변수를 선언하세요
  int age = ?;
  bool hasParentalConsent = ?;
  
  // 이 사람이 게임을 할 수 있는지 확인하세요
  bool canPlayGame = age >= ? || hasParentalConsent;
  
  // 초기 결과를 출력하세요
  print("Age: $age");
  print("Has parental consent: $hasParentalConsent");
  print("Can play game: $canPlayGame");
  
  // 부모 동의 상태를 변경하세요
  hasParentalConsent = ?;
  canPlayGame = age >= 18 ? hasParentalConsent;
  
  // 업데이트된 결과를 출력하세요
  print("\nAge: $age");
  print("Has parental consent: $hasParentalConsent");
  print("Can play game: $canPlayGame");
}
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

기초의 모든 레슨