//定義變量
VAR
nStart :ARRAY[1..100]OF BOOL;
nWord :ARRAY[1..200]OF INT;
nWord1 :ARRAY[1..100]OF INT;
i :INT;
l :INT;
q :INT;
END_VAR
//程序
//賦值
IF nStart[1] THEN
FOR i:=1 TO UINT_TO_INT(SIZEOF(nWord)/2) DO
nWord:=1000-i;
END_FOR
nStart[1]:=FALSE;
END_IF
//冒泡排序
IF nStart[2] THEN
FOR i:=1 TO UINT_TO_INT(SIZEOF(nWord)/2) DO
FOR l:=1 TO UINT_TO_INT(SIZEOF(nWord)/2)-i DO
IF nWord[l+1]<nWord[l] THEN
q:=nWord[l+1];
nWord[l+1]:=nWord[l];
nWord[l]:=q;
END_IF
END_FOR
END_FOR
nStart[2]:=FALSE;
END_IF