For Beginners

Lesson 11/18

Repetitive Tasks as Procedures

Sometimes identical parts of the code are used in several places. You can change them into a procedure and then just call it where needed.

In the example from the previous lesson you can take the code responsible for changing the font size (opening the Font dialog and entering new font size there), turn it into a procedure named changefont, and then call it from within the loop, which increases the ♥fontsize variable:

program notepad
keyboard Hello⋘enter⋙world!
for ♥fontsize from 10 to 100 step 10
    call changefont
end for

procedure changefont
	keyboard ⋘alt+o⋙f
	window font
	keyboard ⋘tab 2⋙♥fontsize⋘enter⋙
end procedure

In the next lesson you will learn how to call a procedure with a parameter.