So far in this module, you’ve written snippets of code that perform tasks such as arithmetic, printing out song lyrics, making value comparisons, etc. Across all these snippets, you used the println() function to print the result.
This function took a primitive input, a String, as its argument and printed it on the console. In this lesson, you’ll dive deeper into functions and learn how to create functions to facilitate reusability in your code and avoid repetition. You’ll also learn how to call the functions, pass arguments, get return values etc.
In programming, a function is a block of code that encapsulates a piece of behavior that runs only when called and can be executed multiple times. This block of code has a few key features.
Simplicity - Isolating the related piece of logic in a program reduces its complexity and makes it much simpler to read.
Reusability - You make your logic reusable by extracting your logic into functions. The code is only written once but can be used in multiple places with different outputs.
Modularity - By breaking down your code into smaller functions, you also aid in the maintenance of your code and facilitate debug issues by narrowing down the scope.
See forum comments
This content was released on Apr 10 2024. The official support period is 6-months
from this date.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Quiz: Leverage Control Flows
Next: Instruction
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.