Comments in AutoIt

Comments are useful when you explain your code to others, and when you want to out-comment bits of code for testing purposes. Find out how to use them in this article.

7742 views

Edited: 2019-11-03 21:21

There is a few ways to write Comments in AutoIt. You can either use semicolon (;) for single line comments, or you can use #comments-start + #comments-end for block comments.

Comments can be useful when you want to describe your code, or comment out bits of code when testing. Do not just use comments to explain the obvious. Generally, only the complex parts of your code should warrant further explanation.

Comments can also be useful for beginners when they are learning AutoIt, when used as small reminders about their code.

The below example shows how to write a Block Comment:

#comments-start
  MsgBox(4096, "", "This message box has been commented out, and should not be displayed when the script is run.")
#comments-end

sleep(1000) ; Code outside of the block comment

To write single-line comments, use the semicolon, like demonstrated below:

; MsgBox(4096, "", "This message box has been commented out, and should not be displayed when the script is run.")

Abbreviated Keywords

You can also use the abbreviated keywords #cs and #ce when writing block comments, they are simply a short-hand way of writing block comments, which can be very useful. Example below:

#cs
  Just a test comment

  MsgBox(4096, "", "This message box has been commented out, and should not be displayed when the script is run.")
#ce

sleep(1000) ; Code outside of the block comment

Links

  1. Language Reference - Comments – autoitscript.com
  2. Keyword #comments-start – autoitscript.com

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials