markdown
プログラミングの基本md bd150c5
lecture/information/programming/introduction-to-programming.lecture.n.md
Download PDF

プログラミングの基本きほん

date2026-07-14document_iddoc_f0e88254a7ce6fe5b40abf46ade12832descriptionプログラムを入力から出力を生成する手続として捉え、状態、制御フロー、分岐、反復、関数の基本を説明する。prerequisites四則演算 / 条件の読み取り / 手順の分解type講義statusactiverelateddata/lecture/information/information-engineering-portal.lecture.n.md / data/lecture/information/programming-languages/foundation/introduction-to-functional-programming.lecture.n.md / data/lecture/information/algorithm/foundation/computational-complexity-basics.lecture.n.md / data/lecture/information/algorithm/foundation/recursion-basics.lecture.n.md
informationprogrammingundergraduatelecture
data/lecture/information/information-engineering-portal.lecture.n.md

1導入どうにゅう

この講義こうぎでは、プログラムを、入力にゅうりょくって出力しゅつりょく生成せいせいする手続てつづきとして説明せつめいする。その実行過程じっこうかてい状態じょうたい制御せいぎょフローによって記述きじゅつし、変数へんすう条件分岐じょうけんぶんき反復はんぷく関数かんすう役割やくわり解説かいせつする。

2基本用語きほんようご

入力にゅうりょくInputとは、プログラムが計算けいさん使用しようするために外部がいぶからるデータである。出力しゅつりょくOutputとは、プログラムが計算結果けいさんけっかとして外部がいぶ提示ていじするデータである。画面がめんへの表示ひょうじ、ファイルの読書よみかき、ネットワーク通信つうしん入出力にゅうしゅつりょくInputoutput; IOれいである。

状態じょうたいStateとは、ある実行時点じっこうじてんにプログラムが保持ほじするあたい総体そうたいである。変数へんすうVariableとは、プログラムからあたい参照さんしょうするための名前なまえである。代入だいにゅうゆる変数へんすうでは、対応たいおうするあたい更新こうしんできる。

制御せいぎょフローControl flowとは、プログラムの各命令かくめいれい実行じっこうする順序じゅんじょである。条件分岐じょうけんぶんきConditional branch条件じょうけん真偽しんぎおうじてつぎ処理しょり選択せんたくし、反復はんぷくIteration指定していした条件じょうけんもと処理しょり反復はんぷくする。

関数かんすうFunctionとは、引数ひきすうとして入力値にゅうりょくちり、一連いちれん処理しょり実行じっこうして返値かえりちかえす、名前なまえけたプログラム構成要素こうせいようそである。言語げんごによっては引数ひきすうまたは返値かえりちたない関数かんすう存在そんざいする。

3実行じっこう状態遷移じょうたいせんいとして記述きじゅつする

状態じょうたいSひとつの命令めいれいc とすると、命令めいれい実行じっこう

(c,S)S

という状態遷移じょうたいせんいとして表現ひょうげんできる。たとえば、状態じょうたい Sx=2 のとき、代入だいにゅう x := x + 1x=3 であるあたらしい状態じょうたい S生成せいせいする。この :=更新こうしんあらわし、数学すうがく等号とうごうとはことなる。

4分岐ぶんき反復はんぷく

if p then A else B は、条件じょうけん pしんなら Aなら B実行じっこうする。while p do A は、pしんであるあいだA実行じっこうしてから p再評価さいひょうかする。反復はんぷく設計せっけいでは、各回かくかい更新こうしんする状態じょうたい継続条件けいぞくじょうけん終了時しゅうりょうじ成立せいりつすべき性質せいしつ区別くべつする。

text
total := 0
for each score in scores:
    total := total + score
return total

このれいでは、scores入力にゅうりょくtotal更新こうしんされる状態じょうたい一部いちぶreturn total出力しゅつりょく決定けっていする処理しょりである。n 点数てんすう一度いちどずつ処理しょりするため、加算回数かさんかいすうn かいである。この評価ひょうか後続こうぞく計算量けいさんりょう講義こうぎ形式化けいしきかする。

5関数かんすうによる分割ぶんかつ

関数かんすうには、処理しょり目的もくてき許容きょようする入力にゅうりょく返値かえりち状態じょうたい入出力にゅうしゅつりょくへの影響えいきょう仕様しようとして付与ふよできる。大規模だいきぼ手続てつづき責務せきむ明確めいかく関数かんすう分割ぶんかつすると、各部分かくぶぶん独立どくりつ検証けんしょうしやすくなる。

ただし、すべての関数かんすう入力値にゅうりょくちだけで返値かえりち決定けっていするとはかぎらない。共有状態きょうゆうじょうたい更新こうしん入出力にゅうしゅつりょく実行じっこうする関数かんすうもある。この相違そういつぎ関数型かんすうがたプログラミングの講義こうぎ詳述しょうじゅつする。

6要点ようてん

  • プログラムの振舞ふるまいは、入力にゅうりょく出力しゅつりょく状態じょうたい制御せいぎょフローを区別くべつすると明確めいかくになる。
  • 条件分岐じょうけんぶんき処理しょり選択せんたくし、反復はんぷく処理しょり再実行さいじっこうする。
  • 関数かんすう処理しょり仕様しよう明確めいかく単位たんい分割ぶんかつする。

7つぎすす講義こうぎ

data/lecture/information/programming-languages/foundation/introduction-to-functional-programming.lecture.n.md data/lecture/information/algorithm/foundation/computational-complexity-basics.lecture.n.md

Programming Fundamentals

data/lecture/information/information-engineering-portal.lecture.n.md

1Introduction

This lecture presents a program as a procedure that receives input and produces output. It describes execution in terms of state and control flow and explains the roles of variables, conditional branches, iteration, and functions.

2Basic Terms

An inputInput is data received from outside a program for use in a computation. An outputOutput is data presented outside the program as a computational result. Screen display, file access, and network communication are examples of inputoutputInputoutput; IO.

A stateState is the collection of values held by a program at a particular point during execution. A variableVariable is a name through which a program refers to a value. If a variable permits assignment, its associated value can be updated.

Control flowControl flow is the order in which the instructions of a program are executed. A conditional branchConditional branch selects the next operation according to the truth value of a condition, while iterationIteration repeats an operation under a specified condition.

A functionFunction is a named program component that receives input values as arguments, executes a sequence of operations, and returns a return value. Some languages also permit functions with no arguments or no return value.

3Describing Execution as State Transitions

If S is a state and c is one instruction, execution can be represented as a state transition

(c,S)S.

For example, if x=2 in state S, the assignment x := x + 1 produces a new state S in which x=3. Here := denotes an update and is distinct from mathematical equality.

4Branching and Iteration

if p then A else B executes A when condition p is true and B when it is false. while p do A executes A while p is true and then reevaluates p. Designing an iteration requires distinguishing the state updated on each iteration, the continuation condition, and the property that must hold at termination.

text
total := 0
for each score in scores:
    total := total + score
return total

In this example, scores is the input, total is part of the updated state, and return total determines the output. Processing each of n scores once performs n additions. A subsequent lecture on computational complexity formalizes this analysis.

5Decomposition into Functions

A function can have a specification that states its purpose, accepted inputs, return value, and effects on state or I/O. Decomposing a large procedure into functions with clear responsibilities makes each component easier to verify independently.

However, not every function determines its return value solely from its input values. Functions may update shared state or perform I/O. The next lecture on functional programming examines this distinction in detail.

6Summary

  • A program's behavior becomes clearer when its input, output, state, and control flow are distinguished.
  • A conditional branch selects an operation, whereas iteration repeats an operation.
  • Functions decompose a computation into units with explicit specifications.

7Next Lectures

data/lecture/information/programming-languages/foundation/introduction-to-functional-programming.lecture.n.md data/lecture/information/algorithm/foundation/computational-complexity-basics.lecture.n.md
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる