교육자를 위해: Subprograms: functions and procedures(Computer Science, Programming)을(를) 위한 바로 쓸 수 있는 수업 슬라이드, 복습 노트 — 수업에 사용하거나, 학습자들이 실시간 게임으로 즐기는 인터랙티브 클래스 활동으로 진행하세요.
A subprogram is a named block of code that does a specific job. They make programs modular, easier to read, test, reuse and maintain, and support team development.
Calling a reusable subprogram
Procedures and functions
A procedure performs actions but does not return a value to the caller.
A functionreturns a value: RETURN result.
Example: FUNCTION area(w, h) RETURN w×h ENDFUNCTION. Call: x = area(3, 4) gives 12.
Parameters and arguments
Parameters are variables in the definition (w, h); arguments are values passed when calling (3, 4). Parameters make subprograms flexible.
Definition and call
Scope
Scope describes where a name can be accessed. A local variable or parameter is accessible within its local scope; a global name has wider program scope under this lesson’s model.
Scope is different from lifetime. Prefer local variables and explicit parameters to reduce unintended changes to shared state.
Names and scope
Structured programming
Use sequence, selection and iteration to organise control flow. Divide a complex solution into focused subprograms with clear interfaces.
A main program can call subprograms; those subprograms may call others.
Library routines
A library routine is a prewritten reusable subprogram provided by a library; some are built into the language environment.
Using a tested routine can save implementation time, but check its parameters, return value and assumptions.
슬라이드
Sign up free to view the lesson slides
Step through every slide for this topic — plus flashcards and revision notes — with a free account.