Instruction 5

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Using Comments

Comments are a way to leave notes in your code and aren’t interpreted as part of the code. These notes could be short or long. For short comments, write your notes after // followed by a space. This type of comment is usually left as a note to self:

// This comment is on top of the variable being described.
const val WEEKLY_INTEREST = 100 // This comment is beside the variable being described.
/* This is known
as a block comment. */
const val WEEKLY_INTEREST = 100
/** This comment is a longer comment giving further information about the variable. */
const val WEEKLYINTEREST = 100
/**
* This comment is longer
* giving further information about the
* variable.
*/
const val WEEKLY_INTEREST = 100
/*
This comment is longer.
It has more information.
This is a valid comment block, but cannot be used with automatic document creation tools.
*/
const val WEEKLYINTEREST = 100

Creating Code Comments

Comments in programming can also exclude a piece of code. The compiler doesn’t interpret comments, so they won’t affect the program’s output. Consider the following example:

// const val WEEKLY_INTEREST = 100 /** This code is said to be commented out.*/
const val WEEKLY_INTEREST = 200
See forum comments
Download course materials from Github
Previous: Instruction 4 Next: Demo