Execute Code from the Editor
You can execute code contained in the IDL editor window in several ways:
Executing Complete Routines
If the editor contains one or more complete named routines (procedures or functions), you can compile and execute the procedure that matches the file's name by pressing F8 or by selecting Run filename (where filename is the file's name) from the Run menu. Routines that are defined in the file before the routine that matches the file's name will also be compiled. (IDL will not compile routines that are defined in the file after the routine that matches the file's name.)
Similarly, if the editor contains a $MAIN$ program, you can compile and execute the program by pressing F8 or by selecting Run filename from the Run menu. Named routines that are defined in the file before the $MAIN$ program will also be compiled.
Executing Selected Lines
If you select one or more lines of code in the editor, you can run the selected lines as individual IDL commands by pressing Shift+F8 or by selecting Run Selected Text from either the Run menu or the editor's context menu. Note that the selected commands must be executable one at a time — executing lines that contain program control statements will cause an error.

If you select one or more lines of code in the editor, you can run the selected lines as individual IDL commands by dragging them to the IDL Command Line view. Note that the selected commands must be executable one at a time — executing lines that contain program control statements will cause an error.

Tip
If you drag commands from an editor to the IDL Command Line view, be sure to select the carriage return at the end of the last line of code. (You'll know the carriage return is selected if the highlight extends to the right edge of the editor window, as shown above.) If the carriage return is not selected, the last line will be placed into the IDL Command Line view, but will not be executed. (Press Enter to execute the final line if this happens.)