일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- c언어
- ===
- 42ecole
- ios개발자
- 짝수와 홀수
- html
- string(from)
- swiftlanguage
- 플레이그라운드 문제풀이
- 라피신
- 이노베이션아카데미
- 42에꼴
- 프로그래머스 문제 풀이
- binary operator
- 추적하기
- 값올리기
- 스위프트
- 프로그래머스
- string from
- 플레이그라운드
- Swift
- 맥
- ==
- unary operator
- ternary operator
- 스위프트공부
- 두 정수 사이의 합
- playgrounds
- !==
- ios
- Today
- Total
목록ALL (34)
minError

purplePortal.isActive = true while !isBlocked { moveForward() while isOnGem { collectGem() if isBlocked { turnLeft() turnLeft() purplePortal.isActive = false } } if isOnClosedSwitch { toggleSwitch() purplePortal.isActive = true turnLeft() turnLeft() } }

greenPortal.isActive = false func switchOn() { moveForward() moveForward() moveForward() turnLeft() moveForward() moveForward() moveForward() toggleSwitch() turnLeft() turnLeft() } for i in 1 ... 3 { switchOn() }
스위프트 언어 에서 while문과 repeat while문의 차이점 먼저, 아래의 예제 코드처럼 입력을 하게 되면? print("---while") var i = 10 while i 코드 수행 > 조건 > 코드수행' repeat while은? '코드 수행 > 조건 > 코드수행 > 조건' 순서대로 인식을 한다고 보시면 됩니다.

let totalGems = randomNumberOfGems var gemCounter = 0 while gemCounter < totalGems { while !isBlocked { if is OnGem { collectGem() gemCounter += 1 } moveForward() } if isBlocked && isBlockedLeft { turnRingt() } else if isBlocked && isBlockedRight { turnLeft() } }

//1. 보석과 스위치의 갯수 세아리는 변수 생성. var swithchCounter = 0 var gemCounter = 0 while switchCounter < gemCounter || switchCounter == 0 { while !isBlocked { //2. 첫번째, 발판 보석 수집하고, 수량 세아리기 if isOnGem { collectGem() gemCounter += 1 } moveForward() } //3. 두번째, 수집한 보석의 갯수만큼 스위치 작동 if isOnClosedSwitch && switchCounter < gemCounter { toggleSwitch() switchCounter += 1 } turnRight() }

let switchCounter = numberOfSwitches //1. 수집한 보석의 개수를 기록하기 위해 변수를 선언합니다. var gemCounter = 0 //2. 보석을 세는 변수의 값과 switchCounter를 비교하여 보석 수집을 중단할 시기를 결정합니다. while gemCounter != switchCounter { while !isBlocked { if isOnGem{ collectGem() gemCounter += 1 } moveForward() } turnRight() }

//1. 2개의 개별적인 변수 생성 (보석을 수집하고, 스위치를 작동시키기 위함) var gemCounter = 0 var onSwitch = 0 //3. 캐릭터가 언제 동작을 중단할지, if구문 or while루프로 조건식 생성 while (gemCounter < 3 || onSwitch < 4) { while !isBlocked { moveForward() //2. 보석을 수집할때 변수를 1씩 증가 시키기 if isOnGem && gemCounter < 3 { gemCounter = gemCounter + 1 } //2. 스위치를 작동할때 변수를 1씩 증가 시키기 if isOnClosedSwitch && onSwitch < 4 { toggleSwitch() onSwitch = onSwitch + 1 ..

//1. gemCounter변수를 선언하고 해당 값을 0으로 설정합니다. var gemCounter = 0 //3. while루프를 사용하여 7개의 모든 보석을 수집할 때까지 수집을 계속하도록 합니다. while gemCounter < 7 { while !isBlocked { //2. 캐릭터가 보석을 수집할 때마다 gemCounter 값을 증가시킵니다. if isOnGem { collectGem() gemCounter = gemCounter + 1 } moveForward() } turnLeft() turnLeft() }

이번 예제는? 숨겨진 보석의 개수를 모를 때, 그 개수를 파악하고 보석을 수집하는 게임입니다. //1. gemCounter에 초기 값 0을 할당합니다. var gemCounter = 0 //2. 코드를 작성하여 각 타일에 보석이 있는지 확인합니다. for i in 1 ... 3 { while !isBlocked { moveForward() //3. 보석을 발견한 경우 해당 보석을 수집하고 gemCounter 값을 1만큼 증가시킵니다. if isOnGem { collectGem() gemCounter = gemCounter + 1 } } turnRight() } While A { B } A인 동안에 B 행동을 하여라 If A { B } 만약에 A 조건이 성립 한다면? B 하여라

추적하기 다음의 업그레이드 버전으로 값을 올려 추적하기 입니다. 바로 이전 단계에서 추적하기의 방법대로 코드를 진행하게 된다면 아래와 같습니다. //1. gemCounter의 초기 값을 0으로 설정하세요. var gemCounter = 0 //2. 수집해야될 보석의 수는 총 5개로, 각각의 보석으로 이동하여 수집하여 gemCounter에 올바른값 할당하기 moveForward() collectGem() gemCounter = 1 moveForward() collectGem() gemCounter = 2 moveForward() collectGem() gemCounter = 3 moveForward() collectGem() gemCounter = 4 moveForward() collectGem() gem..