90
C H A P T E R 5
Scripting
Of course, such a label needs to be defined—and this is the syntax:
restart:
print "script restarted"
While
goto
statements seem to be very convenient and flexible, they im-
pose dangers, too. GOTOs are considered harmful in professional program-
ming because programs tend to become incomprehensible and difficult to
maintain if there are many of them jumping all over the place. So, if you
can, use
if ... then ... else ... endif
,
for ... next
, or
while ...
wend
instead of
goto
. In a tiny script, however, I can’t see why a
goto
should
do any harm.
5.3.8 Subroutines
Subroutines have a very similar syntax as GOTOs, but they can simplify
programs instead of making them more difficult to read. A subroutine
definition starts with a label and ends with a
return
statement:
:waitdisp
do
print "Continue: DISP"
wait_click 3000
until is_pressed "display"
return
This subroutine prompts the user to press the
DISP
key and then waits until
this key is pressed. The advantage of defining such a piece of code in a
subroutine is that it can be called from any location within the script by
using the
gosub
statement:
gosub "waitdisp"
shoot
The
return
command within the subroutine will cause program control to
return to the line after the
gosub
command and execute the instruction
found there.
The CHDK
uBasic
implementation supports nested subroutines to a
depth of 10.
Содержание Camera
Страница 1: ......
Страница 2: ...The Canon Camera Hackers Manual ...
Страница 3: ......
Страница 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Страница 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Страница 25: ...16 CH APTER 3 ...
Страница 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Страница 213: ...204 CH APTER 6 ...
Страница 253: ...244 AP PENDIX ...