If … then … else …

昨天晚上外出用餐。小奕最近坐的習慣很不好,常常動來動去,或是在椅子上椅子下亂扭,於是媽媽想找個誘因讓小奕乖乖坐好。

媽媽:「小奕,如果你乖乖吃完雞腿,而且一直坐在椅子上沒有下來,等一下我請你吃巧克力冰淇淋。」
小奕:「那如果我沒有吃完雞腿,又跑下去呢?
媽媽:「那就沒有冰淇淋吃,而且回家後要讓你屁股開花。」
小奕:「那如果我沒有吃完雞腿,可是沒有跑下去呢?
媽媽:「那就只有一點點冰淇淋吃,可是回家後不會屁股開花。」
小奕:「那如果我有吃完雞腿,可是跑下去呢?
媽媽:「!@#$%$……,那就只有一點點冰淇淋吃,可是回去會屁股開花。」
這時爸爸忍不住插嘴:「媽媽,下次妳出三個條件好了。」

我現在回想一下,這兩個問題到底是不是各自獨立的?還是相關的?如果是獨立的,那應該是:

跑下椅子去﹦屁股開花
吃完雞腿﹦吃冰淇淋

可是我當時的回答應該是「跑下去﹦屁股開花」,可是吃冰淇淋則與其他事情相關,也就是說:

If 跑下去 then
    屁股開花
    If 吃完雞腿 then
        吃一點點冰淇淋
    else
        沒有冰淇淋
    End If
else
    屁股不會開花
    If 吃完雞腿 then
        吃很多冰淇淋
    else
        吃一點點冰淇淋
    End If
End If

唉!小奕問得讓媽媽頭昏眼花且回答得都糊塗了,真是糟糕,我還是接受爸爸的建議,下次開三個條件好了,只是,到時候招架不住的不知道是媽媽還是小奕? ❓ ❓ ❓ 媽媽自己都不大有信心呢!也許,下次要用:
choose case
    case 1
    case 2
    case 3
……

(Visited 3,071 times, 1 visits today)

在〈If … then … else …〉中有 12 則留言

  1. 我朋友說,給小朋友選擇的時候,最好只有「一個狀況,兩個選項」,不要再多了。有的時候小朋友未必是邏輯好,只是因為大人講的話裡面元素多,反應快的小朋友就會追著拆解。

    他家小朋友鬧不吃飯的時候他就來下頭這招:
    猜拳,爸爸贏了,小朋友乖乖吃一口飯。爸爸輸了,小朋友隨便吃她愛吃想吃的東西一口,再吃一口飯。

    他家小朋友是反應很快,很早慧的那種,這招也把她哄得好好的。

    回覆
  2. 好吧,我朋友死不肯自己留言,就是要我寫…

    他說其實只要讓小朋友覺得她有權力做選擇,可以自己決定,她就會很高興,因為她跟“大人一樣“了。小朋友常常只是要這種感覺而已。

    回覆
  3. 瑋芳朋友說的其實真.的.很.對.,只是不知道適不適用於這一陣子的小奕?小奕小時候我倒是用過這個方法,可是最近小奕不太想長大,也不想當大人,嗯!也許過一陣子等他想當大人時就又可以用了。我期待著……

    還有,猜拳真的好用喔!昨晚我們的床邊故事就是猜拳決定的呢!

    謝謝瑋芳朋友!

    回覆
  4. first of all, i agree with 瑋芳 or 瑋芳朋友 about giving less options to little kids. sometimes they just want to make decisions on their own. that’s very true.

    when i see this post, i think about code (sorry, cannot help). is there a way to model all these WITHOUT using IF-THEN-ELSE (or CASE statement which basically is the same type of thing)?

    i am a big fan of design patterns. there is a pattern called State that can help us get rid of these messy, nested if-else conditions. the idea behind this is instead of telling the object what does it deserve (btw, the object = 小奕), let the object tells you what does it deserve (because the object preserves its current state). so we don’t even need one line of if-else statement in the code.

    i find this interesting because it is also true in real life. if it is possible, let the kid tell you what does he/she deserve. because the kid knows very well what he/she has done (i.e. the kid knows what state he/she is in).

    i used this example and implemented a state pattern. here is the code:

    http://www.frorse.com/code/LittleYi.java
    http://www.frorse.com/code/LittleYiReal.java

    回覆
  5. 三哥您真是明察秋毫啊!媽媽總是很有人性的,想想看,外出吃飯的飯後點心不是小孩們最企盼的嗎?媽媽總要想個辦法讓他多少吃一些吧!所以,除非太過分,否則還是會有所通融的啦!

    祖達,我覺得你的想法很有趣也很有道理!其實當時我也沒想那麼多,只是覺得被問得頭昏而已……

    回覆
  6. Andrea, it’s not about you didn’t think that much, it’s me thinking too much. i just cannot get that little geeky guy out of my brain. he keeps telling me to write the code, write the code. so…

    yeah, you can run the code. just compile both of them and issue a command like this: java LittleYiReal

    回覆

發佈留言