Learn Courses My Dashboard

Need more explanation or document of this syntax please (L5 M5)

This is the first time I see this declaretion:

Anyone can explain to me some points:

  • What _ of _ moduleid:Int meant. Can you give me another example please?

  • What break meant. Can you give me another example please?


The function declaration includes a parameter that it passed in and that parameter is moduleid which is of type Int

So you have:

func beginModule(moduleId: Int) {  
// Note that the naming convention should be moduleId rather than moduleid

The break key word is used to “break” out of a for loop.

When you loop through data and you have found what you are looking for, there is no point in looping through the remaining data so to exit the loop, the break key word is used.

1 Like

The _ also means that you don’t need the parameter name at the call site

With the parameter name beginModule(moduleId: 5)

Without it


When you have a underscore, you don’t need the parameter name, but when you don’t have the underscore you do need the parameter name

If you tried to use beginModule(5) you’d get an error

1 Like

Thanks so much!!!

Thanks bro!!!

Thanks Mikaela. I did forget to explain the purpose of the that underscore. It’s easy to overlook that. I know that Chris Ching often uses the underscore but I always change my version so that the parameter name does appear at the call site merely for clarity. Everyone is different.


One more thing please. In this case there are two functions

why do we declare parameter for the second function beginModule (_ moduleId:Int)
but not for the first function getLocalData()

The getLocalData() requires no parameter since all of the instructions inside the function result in the modules array being populated and the styleData being assigned.

1 Like