Comments

In this week’s post, we will be learning how to use comments to explain code!

Comments are used in coding to depict what exactly the code is doing at a certain point in time.  Comments do not affect the code in any way, so you are free to comment wherever and whatever you want (the more, the better!).

Short Comments

Short comments are done by typing a hashtag or a number sign (#) in front of any sequence of characters.  They turn green in Wing IDE!

For, example, a simple math equation program such as:

example math

Can be explained through the comments:

example math commented

These can be used so you can easily sift through a program to find something you are working on or just looking for.

Long Comments

Long comments are done by typing three quotation marks in a row, without spaces (“””) or by typing three apostrophes, also without spaces (”’).  Once you have done this, you will hit the “Enter” key and type in your long comment.  When you are finished typing your comment, you will hit “Enter” again and type three quotation marks or three apostrophes, just as you did in the beginning.  Long comments turn dark red in Wing IDE!

For example, a long comment would be typed at the start of your program and would include information such as your name, your assignment title, your teacher’s name, and the date.

They are used like this:

 

In next week’s post, we will learn a very important concept called “If Statements”.  You will use these for the rest of your programming careers!

2 thoughts on “Comments

Leave a comment