Input/output (入出力) is the combined name for input (入力), where a program takes in data from outside, and output (出力), where it passes the processed result back out.
Input: read in 2 numbers
Process: calculate the average
Output: show the average on screen
The calculated average is sent to the screen. This is the output.
3 / 3
Reading from the keyboard or a file counts as input, while showing something on screen or writing to a file counts as output. If you picture a program running in the order input → process → output, it becomes easy to follow which data comes in and goes out at each point. Even when the processing is split into several parts, you can ask the same question of each part: what goes in and what comes out.
AnalogyIt works like a restaurant: the order slip comes in, the kitchen cooks, and the finished dish goes out to the table.
How to rememberThe short form is I/O: the I of Input and the O of Output joined by a slash, packing both directions, in and out, into one word.
Exam points
ExamWhen processing blocks are chained in series, the output (出力) of one block becomes the input (入力) of the next as it is. Work out the values in order, starting from the first block.
A procedure (手続) is a named set of processing steps; calling it runs the steps inside, and control then returns to the caller without bringing back a result value.
The caller writes the procedure's name
The steps inside the procedure run in order
Control returns to the caller's next step
At the end of the procedure, control goes back to the step after the call, carrying no value with it.
3 / 3
The Japanese word 手続 can also mean a sequence of processing steps in general, not only a building block. In the pseudo-language, a procedure is declared with the type and name of each value it receives inside the parentheses after its name, and no type before the name. When the same processing is needed many times, writing the name is enough to call it.
AnalogyIt is like asking someone to lock up: they check each window and lock in turn and come back, but hand you nothing.
How to rememberThe English word procedure comes from a word meaning to go forward, so think of it as something that moves the processing forward one step at a time.
Exam points
ExamAn algorithm (アルゴリズム) is a set of steps that fixes which processing to do, and in what order, to get the result you want.
ExamIn a procedure (手続) that swaps the values of 2 variables, the value that would be lost when overwritten is first saved to a work variable, and at the end that saved value is put into the other variable.
ExamTo work back from a converted result to the original value, replace each reversible operation such as adding or subtracting with its opposite and trace the steps from the last one backward. Taking a remainder cannot be reversed to a single value, so pick the one that falls within the range the original value could take.
A function (関数) is a named block of processing that hands its result back to the caller as a value.
The caller passes values and calls the function
Inside the function, the received values are processed
Control returns to the caller with the result value
The caller uses the returned value in an assignment or calculation
The caller stores the returned value in a variable or uses it in the next calculation.
4 / 4
A function receives values when it is called, uses them in its processing, and returns the result to the caller. In the pseudo-language it is declared in the form ○整数型: functionName(整数型: name), where 整数型 is the exam notation for integer type, with the return type before the name and the type and name of each received value inside the parentheses after it. Inside the function, return gives back the value written after it and ends the processing.
AnalogyIt is like the square root key on a calculator: enter a number, press the key, and the result of a fixed calculation comes back.
How to rememberIn Japanese it was once written 函数, and 函 means box. Picture a box that gives back a result when you put a value in.
Exam points
ExamIf return runs partway through a loop, the function (関数) ends at that moment and the remaining iterations do not run.
Mix-upA procedure (手続) returns no value when called, but a function (関数) does, so a function call can be written on the right-hand side of an assignment or inside an expression.
An argument (引数) is a value you pass to a procedure or function when you call it, for it to use in its processing.
Position
Name in the declaration's parentheses
Value passed in the call
1st
x
8
2nd
y
4
Seen from the block's side, arguments are its input. The declaration lists the names to receive inside its parentheses, and the caller writes values in that same order to pass them in. Changing the values passed in gets a different result from the same block.
AnalogyIt is like setting the original and the number of copies on a copier and getting exactly that output. The original and the copy count are the arguments.
Exam points
ExamA block can take more than one argument (引数) and can combine their values to choose between different processing paths.
ExamAn argument (引数) can be an array as well as a single number. Inside the block, each element of the received array is referred to by its element number.
A return value (戻り値) is the value a function gives back to the caller as its result, and it is the block's output.
Type written before the name in the declaration
Example of a returned value
Integer type
42
Boolean type
true or false
String type
"ABC"
The type of the return value matches the type written before the name in the function's declaration line. The caller can assign the returned value to a variable or use it for display or the next calculation.
AnalogyIt is like clothes left at a dry cleaner coming back finished: the item you get back is the return value.
How to rememberIn English it is a return value, the same word as return, the pseudo-language instruction that gives a value back, so look after return to see what comes back.
Exam points
ExamIn a function (関数) that returns only after its loop ends, the return value (戻り値) is what you get by following the changes through every pass of the loop to the end.
ExamA return value (戻り値) is not limited to numbers. Some functions (関数) return a Boolean (論理型) value meaning true or false, or a string (文字列型) value made of a sequence of characters.
Mix-upAn argument (引数) is a value that goes from the caller into the block, and a return value (戻り値) is a value that comes back from the block to the caller.
Inside the parentheses after the name, in both the declaration and the call
After return inside the function
Role in input/output
Input to the block
Output from the block
Key points
A program processes input from outside and outputs the result, and when blocks are connected, the output of one block is the input of the next.
Once processing is named as a block, writing its name is enough to use the same processing again and again.
In a pseudo-language declaration line, the type before the name is the return type, and the parentheses after the name hold the type and name of each value received.
Values written in a call go into the arguments in declaration order, and the value a function returns is whatever is written after return.