function的練習,孤單。

Robson Hsieh
2 min readApr 10, 2018

--

func這個指令可將許多具有規則重複的指令變成一個函數,蠻有模組化的概念,還是它就是? 要用一首歌的歌詞來思考練習func的指令,於是就選用這首知名的DJ歌曲吧。

Alan Walker Alone

歌詞:

Lost in your mind
I wanna know
Am I losing my mind?
Never let me go

If this night is not forever
At least we are together
I know I’m not alone
I know I’m not alone
Anywhere, whenever
Apart, but still together
I know I’m not alone
I know I’m not alone

I know I’m not alone
I know I’m not alone

Unconscious mind
I’m wide awake
Wanna feel one last time
Take my pain away

If this night is not forever
At least we are together
I know I’m not alone
I know I’m not alone
Anywhere, whenever
Apart, but still together
I know I’m not alone
I know I’m not alone

以func的概念,改編如下:

func notalone1 () {

print( “I know I’m not alone” )

print( “I know I’m not alone” )

}

func notalone2 () {

print( “I know I’m not alone” )

print( “I know I’m not alone” )

print( “I know I’m not alone” )

print( “I know I’m not alone” )

}

func part1 () {

print( “Lost in your mind” )

print( “I wanna know” )

print( “Am I losing my mind?” )

print( “Never let me go” )

print( “If this night is not forever” )

print( “At least we are together” )

}

func part2 () {

print( “Anywhere, whenever” )

print( “Apart, but still together” )

}

func part3 () {

print( “Unconscious mind” )

print( “I’m wide awake” )

print( “Wanna feel one last time” )

print( “Take my pain away” )

print( “If this night is not forever” )

print( “At least we are together” )

}

func part4 () {

print( “Anywhere, whenever” )

print( “Apart, but still together” )

}

part1 ()

notalone1 ()

part2 ()

notalone2 ()

part3 ()

notalone1 ()

part4 ()

notalone2 ()

然後也確定執行無誤。

playground

--

--

Robson Hsieh

一位資訊遊民的學習部落格,記錄學習後的心得。