Functions · 함수
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
A function returns one value
- A function is like a procedure, and it also hands one value back.
- The definition says the type of that value:
RETURNS INTEGER. RETURNsets the value. It is normally the last line of the function.
한국어
function은 하나의 값을 반환함
- function은 procedure와 유사하며, 하나의 값을 반송하기도 합니다.
- 정의문은 해당 값의 타입을 명시합니다:
RETURNS INTEGER. RETURN은 값을 설정합니다. 일반적으로 함수의 마지막 줄입니다.
FUNCTION Square(N : INTEGER) RETURNS INTEGER
RETURN N * N
ENDFUNCTION
OUTPUT Square(6)
English
Do not write CALL
- A function is used inside an expression, where its returned value is needed.
CALLis only for a procedure.- Parameters of a function are passed by value. The guide says not to use
BYREFon a function.
한국어
CALL을 쓰지 마십시오
- function은 expression 내에서 사용되며, 반환된 값이 필요합니다.
CALL은 procedure에만 해당합니다.- function의 매개변수는 by value로 전달됩니다. 가이드에서는 function에
BYREF을 사용하지 않도록 말합니다.
FUNCTION Max(Number1 : INTEGER, Number2 : INTEGER) RETURNS INTEGER
IF Number1 > Number2 THEN
RETURN Number1
ELSE
RETURN Number2
ENDIF
ENDFUNCTION
OUTPUT Max(10, 24)
English
Common mistakes
RETURNbelongs inside the function. Outside it, there is nothing to return to.- The call
Square(6)is not a complete statement on its own.OUTPUT Square(6)is.
한국어
흔한 실수
RETURN은 function 내부에 있어야 합니다. 외부에서는 반환할 것이 없습니다.- 호출
Square(6)자체로는 완전한 문장이 아닙니다.OUTPUT Square(6)은 완전한 문장입니다.
English
Now you try
- Write a function and use its result in
OUTPUT.
한국어
이제 직접 해보기
- function을 작성하고 그 결과를
OUTPUT에서 사용하십시오.
Write Square so that OUTPUT Square(6) prints 36. · Square을 작성하여 OUTPUT Square(6)이 36을 출력하도록 하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Write Max to return the larger of two integers. OUTPUT Max(10, 24) should print 24. · 두 정수 중 큰 값을 반환하는 Max을 작성하십시오. OUTPUT Max(10, 24)이 24을 출력해야 합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.