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

From Lazarus wiki
Jump to navigationJump to search
Line 14: Line 14:
 
<tt>Variable_List</tt> はカンマで区切られた変数識別子のリストである。
 
<tt>Variable_List</tt> はカンマで区切られた変数識別子のリストである。
  
<tt>read</tt>は特殊な行末文字で行が区切られた一連の文字として入力を扱う。一方、<tt>readln</tt>は値を読み込んだ後、行末文字があるとその後に自動的に移動することで次の行へと飛ぶ。
+
<tt>read</tt>は特殊な行末文字で行が区切られた一連の文字として入力を扱う。一方、<tt>readln</tt>は値を読み込んだ後、行末文字の後に自動的に移動することで次の行へと飛ぶ。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
readln (Variable_List);
 
readln (Variable_List);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
ユーザから次のような入力を受け取ったとしよう。<tt>a, b, c,</tt>、そして<tt>d</tt> はみんな整数である。
+
ユーザから次のような入力を受け取ったとしよう。<tt>a, b, c,</tt>そして <tt>d</tt> はみんな整数である。
 
  45 97 3
 
  45 97 3
 
  1 2 3
 
  1 2 3
  
ここでは<tt>read</tt>と<tt>readln</tt> の命令文の例を、適当な変数に読み込まれた値と共に示す。
+
ここでは <tt>read</tt> と <tt>readln</tt> の命令文の例を、適当な変数に読み込まれた値と共に示す。
 
{| class="wikitable"
 
{| class="wikitable"
 
|-  
 
|-  
Line 45: Line 45:
 
  8352.38
 
  8352.38
  
When an integer is read from the above input, its value becomes <tt>8352</tt>. If, immediately afterwards, you read in a character, the value would be '<tt>.</tt>' since the read head stopped at the first alphanumeric character.
+
上の入力から整数が読み込まれると、その値は <tt>8352</tt> となる。 If, immediately afterwards, you read in a character, the value would be '<tt>.</tt>' 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 '<tt>.</tt>' and stops since it couldn't find any data to read.
 
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 '<tt>.</tt>' and stops since it couldn't find any data to read.

Revision as of 11:12, 4 August 2015

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

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

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

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

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

read (Variable_List);

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

readは特殊な行末文字で行が区切られた一連の文字として入力を扱う。一方、readlnは値を読み込んだ後、行末文字の後に自動的に移動することで次の行へと飛ぶ。

readln (Variable_List);

ユーザから次のような入力を受け取ったとしよう。a, b, c,そして d はみんな整数である。

45 97 3
1 2 3

ここでは readreadln の命令文の例を、適当な変数に読み込まれた値と共に示す。

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);

整数として読む場合、数字が見つかるまでスペースはすべて読み飛ばされる。そうして、数字ではない文字(空白に限らず)が出てくるまで続くすべての数字が読まれる。

8352.38

上の入力から整数が読み込まれると、その値は 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