Functions and Modular Programming

Lesson 5 of 20

Chop big problems into named, reusable methods — pass values in, get results back, and keep main short and sweet.

The big picture

One job per method

A method is a named mini-program: values come in through parameters, a result comes out through return.

One job per method

A method packages a named task — greet(), add(), printLine() — and you can call it anywhere, any number of times.

Parameters feed it

Values passed in (arguments) let one method work on many different inputs.

Return sends back

return hands a result to the caller; void methods just do their job and end.

Modular programs

Big problems split into small methods are easier to write, test and fix.