Skip to content
Coding Fanatic
  • Android Development
  • News and Reviews
  • Road2Pro
  • Tutorials
  • Services
  • About

Repetition and Functions – Day 89 of 100 Days…

  • December 17, 2020December 18, 2020
  • by Richard Clarke

Repeat statements are way easier than loops!

You can find more on this in the video at the bottom of the page.

Similar to loops, repeat statements are used to repeat a block of code a set number of times. However, repeat statements explicitly tell the Kotlin compiler how many times to repeat a block of code. (click below). 

In this example, when the printBorder() function is invoked, it uses a repeat method to print a border of 23 equals signs (=) followed by a new line. 

The repeat statement makes it easier to automate a single task. Simply pass the number of iterations and the Kotlin interpreter takes care of the rest.

Speaking of passing numbers, Kotlin has a similar syntax to Java when it comes to passing arguments to functions. The function is invoked using an argument, however, function headers are written a bit differently.

The function header is the beginning of a function. It is used to define how the function will accept arguments (called parameters). (Click below)

In this example, the function header uses the syntax parameterName: DataType to denote parameters. This differs from Java where the syntax is DataType parameterName.

It is worth mentioning that while assigning values to variables in Kotlin, you only need the value/expression and the val keyword. However, function headers require you to explicitly include data types for each parameter.

Lastly, it appears the Kotlin playground has finally updated to the latest version of Kotlin, 1.4.2 (click below).

It shouldn’t have a major effect on what I’m working on, but it’s worth noting that it’s up-to-date.

While I’ve enjoyed using the Kotlin playground, it’s time I set up Kotlin locally. Next week, I plan to livestream while I attempt to configure my local environment. I’ll post the official date on Twitter and LinkedIn so stay tuned!

Sources:
Android Basics: Introduction to Kotlin
Kotlin Playground
Kotlin logo image
Background acryllic artwork (top right)
Background painting (top left)

Related

Reliable Transportation – Road 2 Pro 4
Your Degree is NOTHING to me! Road 2 Pro 5
Richard Clarke
Richard is currently a developer using Java and Android Studio to build custom applications for Android. Richard tutored in mathematics at Montgomery College, and worked in Information Technology before entering the Software Development industry as a Quality Engineer.
100daysofcode Android AndroidDev development Invocation Invoke Java kotlin Kotlin Playground Method software software development

Related articles

Your New Favorite Stopwatch App!…
Two for Two BABY! 7…
…But the App is for…
Play Store Blues – 5…
Top 4 Tips for Android…
No Dice – 3 of…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • GitHub
  • YouTube
  • X
  • Instagram
  • LinkedIn
My Tweets

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • X
  • GitHub
  • LinkedIn
  • YouTube

Archives

Theme by Colorlib Powered by WordPress