Ad space (banner)
๐ŸŽObjective-C Lessons
Lesson 17 / 68

Writing comments

This lesson covers writing comments in Objective-C, with the aim of making the intent of your code clear to others and to yourself.

A comment is a note for humans that has no effect on execution. // comments one line and /* */ comments several.

The sample code shows all three patterns: a whole-line comment, an explanation added at the end of a line as in NSInteger price = 100; // product price, and a multi-line comment wrapped in /* */.

A common early stumble is writing so many comments that the code becomes harder to read. Recording why something is needed is valuable; restating what the code plainly says is not.

In professional work, comments are also used constantly to disable code temporarily — commenting out.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Objective-C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)