程式示例
以ASP為例
第一種:
<%
if 條件 then
response.write "2"
response.write "5"
response.write "4"
response.write "2"
response.write "1"
response.write "2"
response.write "3"
else
response.write "else"
end if
%>
第二種:
<%
if 條件 then
call isdo '調用子過程
else
response.write "else"
end if
sub isdo
response.write "2"
response.write "5"
response.write "4"
response.write "2"
response.write "1"
response.write "2"
response.write "3"
end sub
%>
這兩種的施行結果是一樣的,但是第二種代碼顯的直觀很多,可讀性強。因為你中間的代碼如果不止這些比這多得多的話,讀程式的人就很難找到ELSE,這時候最好用子過程。