23-1 ������

Ynإߤjε{A{XNnҲդơ]Modularized^HK䭫ƨϥΫס]Reusability^C]bg WSH {XɡAڭ̴NӪ`N{XƩʡAó]kNƥX{gơ]κ٨禡^AHKƨϥΡC

H WSH ҡAUCdҥiϥΨ sum() ӺX 1 [ n `MG

lɡ]sum01.js^G]ǦϰUYi^
// ϥΨƭp 1 [ n `M

function sum(n) {
	var i, total=0;
	for (i=1; i<=n; i++)
		total = total + i;
	return(total);
}

n = 40;
WScript.Echo("1+2+...+" + n + " = " + sum(n) + "\n");

ܵGpUG

1+2+...+40 = 820 b WSH AƪwqiHbP@ɮתBA]ڭ̤]iHIsơAMAwqơAdҦpUG

lɡ]sum02.js^G]ǦϰUYi^
// ϥΨƭp 1 [ n `M

n = 40;
WScript.Echo("1+2+...+" + n + " = " + sum(n) + "\n");

function sum(n) {
	var i, total=0;
	for (i=1; i<=n; i++)
		total = total + i;
	return(total);
}

ұo쪺GOۦPC

ۦP\઺ơAY VBScript ӼgA{dҦpUG

lɡ]sum01.vbs^G]ǦϰUYi^
' ϥΨƭp 1 [ n `M

function sum(n)
	dim i, total
	total = 0
	for i = 1 to n
		total = total + i
	next
	sum = total
end function

n = 40
WScript.Echo("1+2+...+" & n & " = " & sum(n) & chr(13) & chr(10))

ұo쪺GO@˪C

P˪Abϥ VBScript WSH ɡA]iHNƪwq᭱AbAحzC


JScript {]pPΡGΩ WSH