반복문

이승덱·2021년 7월 21일

CPP

목록 보기
9/70
#include <iostream>

using namespace std;

//반복문

int main()

{

 //while문

 //특정 조건까지 반복해야하는 상황에 사용

 //ex) 게임을 끌때까지 계속 게임을 싱행

 //ex) 목적지에 도달할 때 까지~ 계속 이동하라

 

 int round = 1;

 int hp = 100;

 int damage = 20;

 while (true) {

 hp -= damage;

 if (hp < 0)

 hp = 0;

 cout << "Round " << round <<"몬스터 체력"<<hp<< endl;

 if (hp == 0) {

 cout << "몬스터 처치" << endl;

 break;

 }

 if (round == 5) {

 cout << "제한 라운드 종료" << endl;

 break;

 }

 round++;

 }

 for (int i = 1;i <= 10;i++) {

 bool isEven = (i % 2 == 0);

 if (isEven)

 continue;

 cout << i << endl;

 }

}
profile
공부 기록용 블로그입니다

0개의 댓글