diff --git a/documents/AboutKotlin_2.md b/documents/AboutKotlin_2.md index 6d254f9ea9dff00abb59e0593f4e19f32b5149e5..9e4eb5921b67237a139c7641b74cdcf911703831 100644 --- a/documents/AboutKotlin_2.md +++ b/documents/AboutKotlin_2.md @@ -52,7 +52,7 @@ fun main(){ - **downTo 함수** + **downTo <u>함수</u>** 감소되는 연속된 값 범위 생성한다. @@ -66,7 +66,7 @@ fun main(){ - **until 함수 ** + **until <u>함수</u> ** 끝값이 정확히 지정되지 않을 때 사용된다. until로 지정된 범위의 상한값은 제외시킨 범위를 생선한다. @@ -87,7 +87,25 @@ fun main(){ -#### 기타 +#### 2. when 표현식 + +when 표현식은 <u>괄호 안에 있는 인자</u>(argument)와 <u>중괄호 안에서 지정 지정한 조건값</u>들을 기준으로 == 비교 연산자로 두 값을 각각 비교한다. + +```kotlin +fun main(){ + val healthStatus = when(healthPoints){ + 100 //-> "최상의 상태" + in 50..99 //-> "약간의 찰과상 존재" + else -> "최악의 상태" + } + println(userName + " " + healthStatus) +} +``` + 코*드 해석: →(화살표)의 왼쪽부분이 healthPoints 변수의 값이 될 수 있는 범위를 나타낸다. 즉, **in 키워드**를 통해서 healthPoints가 해당 범위에 속하는지 검사한다.* + + + +#### 3. 기타 * 비교연산자 @@ -151,5 +169,23 @@ fun main(){ +* 문자열 템플릿(string template) + + '**$ + 변수**'로 작성하여 문자열 안에 변수의 값을 포함시켜 출력할 수 있다. + + ```kotlin + fun main(){ + val userName = "Joylish" + var healthPoints = 10 + println("$name의 건강점수는 $healthPoints이다.") + } + ``` + + + + **(+a) 문자 표현식** + + 문자열 내부에서 '**$ + 중괄호'**를 활용해서 중괄호 안에 있는 표현식을 실행한 후 그 결과를 문자열에 삽입한다. + diff --git a/documents/captures/TextExpression.png b/documents/captures/TextExpression.png new file mode 100644 index 0000000000000000000000000000000000000000..7f7ac77e700732b783ac0e4161a2b44c82889941 Binary files /dev/null and b/documents/captures/TextExpression.png differ diff --git a/practice/NyetHack/.idea/workspace.xml b/practice/NyetHack/.idea/workspace.xml index 6f73e7a29a19ffd0b405e372ac2f8a282c58bee8..ac2f008dda5b052c0b4b796a2b363296ed1ebd61 100644 --- a/practice/NyetHack/.idea/workspace.xml +++ b/practice/NyetHack/.idea/workspace.xml @@ -1,7 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ChangeListManager"> - <list default="true" id="c8fe5052-ef54-4670-996b-63e6701eba50" name="Default Changelist" comment="" /> + <list default="true" id="c8fe5052-ef54-4670-996b-63e6701eba50" name="Default Changelist" comment=""> + <change beforePath="$PROJECT_DIR$/../../documents/AboutKotlin_2.md" beforeDir="false" afterPath="$PROJECT_DIR$/../../documents/AboutKotlin_2.md" afterDir="false" /> + </list> <ignored path="$PROJECT_DIR$/out/" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="SHOW_DIALOG" value="false" /> @@ -81,6 +83,7 @@ </panes> </component> <component name="PropertiesComponent"> + <property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="settings.editor.selected.configurable" value="configurable.group.appearance" /> </component> @@ -131,7 +134,6 @@ </component> <component name="ToolWindowManager"> <frame x="762" y="0" width="781" height="830" extended-state="0" /> - <editor active="true" /> <layout> <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18307906" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />