Thuta Learning
Swift
ExercisesProgrammingအခြေခံ

Exercise Set 1: Basic Syntax Practice

Swiftသင်ခန်းစာ 3340 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Exercise Set 1: Basic Syntax Practice ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
  • Nil, error, boundary နဲ့concurrency cases စမ်းနိုင်ရန်
  • Safe, testable Swift code ရေးနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

Exercise Set 1: Basic Syntax Practice ကို ရိုးရိုးလေးနားလည်မယ်

ဒီ lesson က teaching content အသစ် မဟုတ်ဘဲ Basic chapter မှာ သင်ခဲ့တဲ့ syntax fundamentals တွေကို လက်တွေ့ practice လုပ်ဖို့ ရည်ရွယ်ထားတဲ့ exercise set ဖြစ်ပါတယ်။ Task တစ်ခုချင်းစီဟာ concept တစ်ခုတည်းအပေါ် focus ထားပြီး copy-paste မလုပ်ဘဲ ကိုယ်တိုင်ရေးမှ အကျိုးရှိမှာပါ။ Difficulty level က warm-up အနေနဲ့ ရိုးရှင်းအောင် ထားထားပြီး Exercise Set 2 မှာ Intermediate/Advanced level ကို တက်သွားပါလိမ့်မယ်။ အောက်က task တွေကို ဖြေပြီးရင် code ကို run ပြီး output ကို prediction လုပ်ထားတာနဲ့ တိုက်စစ်ကြည့်ပါ။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

switch statement မှာ range pattern (60...79 လို) သုံးရမှာကို if-else chain ရှည်ရှည်နဲ့ ရေးနေတတ်ကြတယ်

ဖြစ်လေ့ရှိတဲ့အမှား

dictionary loop လုပ်တဲ့အခါ (key, value) tuple ဖြစ်တာကို မသိဘဲ .values ပဲ ခေါ်ပြီး key ကို လွဲချော်တတ်ကြတယ်

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

Exercise Set 1: Basic Syntax Practice ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။

Mental Model
  1. လိုအပ်ချက်
  2. စဉ်းစားပြီး implement
  3. စမ်းသပ်ပြီးရှင်းပြ

Exercise Set 1: Basic Syntax Practice ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

swift
// Task 1
func isEven(number: Int) -> Bool {
    // TODO: implement
    return false
}

// Task 2
let fruits = ["Apple", "Banana", "Mango"]
// TODO: for-in loop with index

// Task 3
let scores: [String: Int] = ["Aung": 80, "Su": 65, "Ko Ko": 90]
// TODO: calculate average

// Task 4
func gradeCategory(score: Int) -> String {
    // TODO: switch statement with ranges
    return ""
}

print(isEven(number: 4))
print(gradeCategory(score: 75))

Exercise Set 1: Basic Syntax Practice ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။

Code ကို အဆင့်လိုက်ဖတ်မယ်

  1. လိုအပ်ချက်// Task 1

    ဒီ lesson က teaching content အသစ် မဟုတ်ဘဲ Basic chapter မှာ သင်ခဲ့တဲ့ syntax fundamentals တွေကို လက်တွေ့ practice လုပ်ဖို့ ရည်ရွယ်ထားတဲ့ exercise set ဖြစ်ပါတယ်။ Task တစ်ခုချင်းစီဟာ concept တစ်ခုတည်းအပေါ် focus ထားပြီး copy-paste မလုပ်ဘဲ ကိုယ်တိုင်ရေးမှ အကျိုးရှိမှာပါ။ Difficulty level က warm-up အနေနဲ့ ရိုးရှင်းအောင် ထားထားပြီး Exercise Set 2 မှာ Intermediate/Advanced level ကို တက်သွားပါလိမ့်မယ်။ အောက်က task တွေကို ဖြေပြီးရင် code ကို run ပြီး output ကို prediction လုပ်ထားတာနဲ့ တိုက်စစ်ကြည့်ပါ။

  2. စဉ်းစားပြီး implementlet scores: [String: Int] = ["Aung": 80, "Su": 65, "K...

    Exercise Set 1: Basic Syntax Practice ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။

  3. စမ်းသပ်ပြီးရှင်းပြprint(gradeCategory(score: 75))

    Exercise Set 1: Basic Syntax Practice example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

Execution Flow
  1. လိုအပ်ချက်
  2. စဉ်းစားပြီး implement
  3. စမ်းသပ်ပြီးရှင်းပြ

Success

Exercise Set 1: Basic Syntax Practice ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

Failure

switch statement မှာ range pattern (60...79 လို) သုံးရမှာကို if-else chain ရှည်ရှည်နဲ့ ရေးနေတတ်ကြတယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ lesson က teaching content အသစ် မဟုတ်ဘဲ Basic chapter မှာ သင်ခဲ့တဲ့ syntax fundamentals တွေကို လက်တွေ့ practice လုပ်ဖို့ ရည်ရွယ်ထားတဲ့ exercise set ဖြစ်ပါတယ်။ Task တစ်ခုချင်းစီဟာ concept တစ်ခုတည်းအပေါ် focus ထားပြီး copy-paste မလုပ်ဘဲ ကိုယ်တိုင်ရေးမှ အကျိုးရှိမှာပါ။ Difficulty level က warm-up အနေနဲ့ ရိုးရှင်းအောင် ထားထားပြီး Exercise Set 2 မှာ Intermediate/Advanced level ကို တက်သွားပါလိမ့်မယ်။ အောက်က task တွေကို ဖြေပြီးရင် code ကို run ပြီး output ကို prediction လုပ်ထားတာနဲ့ တိုက်စစ်ကြည့်ပါ။

လေ့ကျင့်ခန်းများ

Task 1: function isEven(number: Int) -> Bool ကို ရေးပြီး even ဆိုရင် true ပြန်ပါ။ Task 2: fruits ဆိုတဲ့ [String] array တစ်ခု ဆောက်ပြီး for-in loop နဲ့ index နဲ့ item ကို "1. Apple" ပုံစံ print ထုတ်ပါ။ Task 3: scores ဆိုတဲ့ [String: Int] dictionary (student name to score) ဆောက်ပြီး loop နဲ့ average ကို calculate လုပ်ပါ။ Task 4: switch statement သုံးပြီး integer input တစ်ခုကို 0-59 fail, 60-79 pass, 80-100 excellent ဆိုပြီး category classify လုပ်တဲ့ function ရေးပါ။

Code နမူနာ

swift
// Task 1
func isEven(number: Int) -> Bool {
    // TODO: implement
    return false
}

// Task 2
let fruits = ["Apple", "Banana", "Mango"]
// TODO: for-in loop with index

// Task 3
let scores: [String: Int] = ["Aung": 80, "Su": 65, "Ko Ko": 90]
// TODO: calculate average

// Task 4
func gradeCategory(score: Int) -> String {
    // TODO: switch statement with ranges
    return ""
}

print(isEven(number: 4))
print(gradeCategory(score: 75))
You should see
isEven(number: 4) က true ပြန်ပေးပြီး၊ fruits list က number ပါတဲ့ line သုံးကြောင်း print ထွက်ကာ၊ gradeCategory(score: 75) က "Pass" ပြန်ပေးသင့်ပါတယ်။

၅ မိနစ် စမ်းကြည့်

Task 4 ကို ပြီးရင် score အနုတ်ကိန်း (-5) ကို input ပေးကြည့်ပြီး invalid case အတွက် "Invalid" ပြန်ပေးအောင် default case ထပ်ထည့်ကြည့်ပါ- 5 minute အတွင်း ဖြေကြည့်ပါ။

သတိလေးတစ်ချက်

Task တစ်ခုစီကို solution မကြည့်ခင် ကိုယ့်ဘာသာ 5 မိနစ်လောက် အရင်ကြိုးစားကြည့်ပါ - error message ကိုယ်တိုင်ဖတ်ပြီး debug လုပ်တဲ့ practice ကသာ Basic concept တွေကို firm ဖြစ်စေပါလိမ့်မယ်။

Real-world usage

လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ

Exercise Set 1: Basic Syntax Practice example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

Exercise Set 1: Basic Syntax Practice example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
swift
// Task 1
func isEven(number: Int) -> Bool {
    // TODO: implement
    return false
}

// Task 2
let fruits = ["Apple", "Banana", "Mango"]
// TODO: for-in loop with index

// Task 3
let scores: [String: Int] = ["Aung": 80, "Su": 65, "Ko Ko": 90]
// TODO: calculate average

// Task 4
func gradeCategory(score: Int) -> String {
    // TODO: switch statement with ranges
    return ""
}

print(isEven(number: 4))
print(gradeCategory(score: 75))

ရလဒ်: Exercise Set 1: Basic Syntax Practice ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်

အရိပ်အမြွက် ကြည့်ရန်

Exercise Set 1: Basic Syntax Practice example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

Quick Quiz 1 / 3

Exercise Set 1: Basic Syntax Practice ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • လိုအပ်ချက် → စဉ်းစားပြီး implement → စမ်းသပ်ပြီးရှင်းပြ
  • Exercise Set 1: Basic Syntax Practice ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
  • switch statement မှာ range pattern (60...79 လို) သုံးရမှာကို if-else chain ရှည်ရှည်နဲ့ ရေးနေတတ်ကြတယ်
  • Exercise Set 1: Basic Syntax Practice example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

The Swift Programming Language — Swift.org

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • switch statement မှာ range pattern (60...79 လို) သုံးရမှာကို if-else chain ရှည်ရှည်နဲ့ ရေးနေတတ်ကြတယ်
  • dictionary loop လုပ်တဲ့အခါ (key, value) tuple ဖြစ်တာကို မသိဘဲ .values ပဲ ခေါ်ပြီး key ကို လွဲချော်တတ်ကြတယ်
  • Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

Exercise Set 1: Basic Syntax Practice example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: isEven(number: 4) က true ပြန်ပေးပြီး၊ fruits list က number ပါတဲ့ line သုံးကြောင်း print ထွက်ကာ၊ gradeCategory(score: 75) က "Pass" ပြန်ပေးသင့်ပါတယ်။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Exercise Set 1: Basic Syntax Practice | Thuta Learning