Difference between revisions of "Basic Pascal Tutorial/Chapter 2/Input/ja"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Input}} 2A - 入力 (著者: Tao Yue, 状態: 原文のまま修正なし) Input is what comes into the program. It can be from the keyboard, the mouse, a file on disk, a ...")
 
Line 3: Line 3:
 
2A - 入力 (著者: Tao Yue, 状態: 原文のまま修正なし)
 
2A - 入力 (著者: Tao Yue, 状態: 原文のまま修正なし)
  
Input is what comes into the program. It can be from the keyboard, the mouse, a file on disk, a scanner, a joystick, etc.
+
入力とはプログラムに入ってくるもののことである。キーボードから入ることもあれば、マウス、ディスクのファイル、スキャナー、ジョイスティックなどなどから入ってくることもある。
  
We will not get into mouse input in detail, because that syntax differs from machine to machine. In addition, today's event-driven windowing operating systems usually handle mouse input for you.
+
マウス入力については詳しく取り上げない。その理由は、文法がマシン次第で異なるからである。加えて、今日のイベント・ドリブンのウインドウOSがたいていマウス入力を扱ってくれるからである。
  
The basic format for reading in data is:
+
データの読み込みの基本フォーマットは以下の通りである。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
read (Variable_List);
 
read (Variable_List);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<tt>Variable_List</tt> is a series of variable identifiers separated by commas.
+
<tt>Variable_List</tt> はカンマで区切られた変数識別子のリストである。
  
 
<tt>read</tt> treats input as a stream of characters, with lines separated by a special end-of-line character. <tt>readln</tt>, on the other hand, will skip to the next line after reading a value, by automatically moving past the next end-of-line character:
 
<tt>read</tt> treats input as a stream of characters, with lines separated by a special end-of-line character. <tt>readln</tt>, on the other hand, will skip to the next line after reading a value, by automatically moving past the next end-of-line character:

Revision as of 17:41, 31 July 2015

български (bg) Deutsch (de) English (en) français (fr) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

2A - 入力 (著者: Tao Yue, 状態: 原文のまま修正なし)

入力とはプログラムに入ってくるもののことである。キーボードから入ることもあれば、マウス、ディスクのファイル、スキャナー、ジョイスティックなどなどから入ってくることもある。

マウス入力については詳しく取り上げない。その理由は、文法がマシン次第で異なるからである。加えて、今日のイベント・ドリブンのウインドウOSがたいていマウス入力を扱ってくれるからである。

データの読み込みの基本フォーマットは以下の通りである。

read (Variable_List);

Variable_List はカンマで区切られた変数識別子のリストである。

read treats input as a stream of characters, with lines separated by a special end-of-line character. readln, on the other hand, will skip to the next line after reading a value, by automatically moving past the next end-of-line character:

readln (Variable_List);

Suppose you had this input from the user, and a, b, c, and d were all integers.

45 97 3
1 2 3

Here are some sample read and readln statements, along with the values read into the appropriate variables.

Statement(s) a b c d
read (a); 45 97
read (b);
readln (a); 45 1
read (b);
read (a, b, c, d); 45 97 3 1
readln (a, b); 45 97 1 2
readln (c, d);

When reading in integers, all spaces are skipped until a numeral is found. Then all subsequent numberals are read, until a non-numeric character is reached (including, but not limited to, a space).

8352.38

When an integer is read from the above input, its value becomes 8352. If, immediately afterwards, you read in a character, the value would be '.' since the read head stopped at the first alphanumeric character.

Suppose you tried to read in two integers. That would not work, because when the computer looks for data to fill the second variable, it sees the '.' and stops since it couldn't find any data to read.

With real values, the computer also skips spaces and then reads as much as can be read. However, many Pascal compilers place one additional restriction: a real that has no whole part must begin with 0. So .678 is invalid, and the computer can't read in a real, but 0.678 is fine.

Make sure that all identifiers in the argument list refer to variables! Constants cannot be assigned a value, and neither can literal values.

previous contents next