|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
If you have a Pascalite, or the ソフトウェア emulation, then there's a separate tutorial for you, covering much of the ground as 現在のd here for the FPC/ TP (人が)群がる.
Pascal comes with a lot of "built in" words, e.g. Begin, End, Program, "If.. Then... Else, Repeat... Until, and LOTS more that you will 会合,会う in 未来 tutorials.
Nonetheless, in the course of many 事業/計画(する)s, you will find yourself feeling that その上の words would be useful. 恐れる not! You can "(不足などを)補う" words, and 追加する them to the language!
Our first example is going to look trivial, but please 耐える with me for a moment.
In an 早期に tutorial we had the に引き続いて program
program hi;
begin
writeln('Hi');
writeln('Bye');
end.
I'm going to change that わずかに, blending into it things which should be familiar. The に引き続いて 名簿(に載せる)/表(にあげる)ing will let you type almost anything, and then you'll get a "Hi" or a "Hello", depending on whether you entered 1 or more characters. And if you enter 999, the program will end. (Ordinarily, you would 誘発する 使用者s, so that they would have a better idea of what is going on, but we'll keep this "lean".)
program UserDefProcs;
var sTmp:string;
begin
repeat
readln(sTmp);
if length(sTmp)=1
then writeln('Hi')//no ; here
else writeln('Hello');
until sTmp='999';
writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.
I hope that is pretty transparent?
If you knew about 使用者-defined 手続きs, you could 達成する the same result with...
program UserDefProcs;
var sTmp:string;
手続き SayHi;
begin
writeln('Hi');
end;
手続き SayHello;
begin
writeln('Hello');
end;
begin //main
repeat
readln(sTmp);
if length(sTmp)=1
then SayHi//no ; here
else SayHello;
until sTmp='999';
writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.
At first ちらりと見ること, this might not seem an 改良.... but once you know your way around the basic structure, it isn't bad, and as your programs become more sophisticated, the breaking up of the program into manageable chunks becomes 必須の. So.... WHAT IS that "basic structure" you need to know your way around?
begin //main
repeat
readln(sTmp);
if length(sTmp)=1
then SayHi//no ; here
else SayHello;
until sTmp='999';
writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.
"SayHi" and "SayHello" are not 基準 Pascal words. They are words we have created ーするために do the 職業 we have in mind for this program. The 指名するs should tell us what they do. We can look at the 詳細(に述べる)s in the part of the program before the main part. It is a classic "divide and 征服する/打ち勝つ" 戦略.
Remember that you can 挿入する new lines and spaces whereever it helps to make something more (疑いを)晴らす. Notice how the indenting and blank lines help make the sections of the code more evident. The "then" and "else" which go with the "if" are 平易な to find. The "until" for the "repeat" is 平易な to find. the 鮮明度/定義s of the two words we made up (before "begin //main") stand out nicely... at least they will, when you get used to reading this stuff!
Let's alter the program so that a blank line and then a line with "===="s appears before each 令状 of "Hi" or "Hello". First we'll do it the dumb, obvious way.
program UserDefProcs;
var sTmp:string;
手続き SayHi;
begin
writeln;
writeln('===============');
writeln('Hi');
end;
手続き SayHello;
begin
writeln;
writeln('===============');
writeln('Hello');
end;
begin //main
repeat
readln(sTmp);
if length(sTmp)=1
then SayHi//no ; here
else SayHello;
until sTmp='999';
writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.
The に引き続いて illustrates that you can even use words you've made up in words you've made up!
program UserDefProcs;
var sTmp:string;
手続き separator;
begin
writeln;
writeln('===============');
end;
手続き SayHi;
begin
separator;
writeln('Hi');
end;
手続き SayHello;
begin
separator;
writeln('Hello');
end;
begin //main
repeat
readln(sTmp);
if length(sTmp)=1
then SayHi//no ; here
else SayHello;
until sTmp='999';
writeln;
writeln('Bye. 圧力(をかける) the Enter 重要な.');
readln;
end.
The only 制限 is that the "手続き separator begin.. end" stuff must appear BEFORE any place you try to use your new word (proper 称する,呼ぶ/期間/用語 for "your new word": 使用者 Defined 手続き). Even in this "trivial" example of the technique, I think you can see an advantage: It saves you typing out the two parts of the "Separator" twice. Half the chance for typos. If you do make a typo, at least the program will run 終始一貫して, with the same "Separator" between "Hi"s and "Hello"s. And a big advantage: If you want to make a change... say use "***" instead of "===", you can... without having to go through the program, and make the same change in several places. Within the 鮮明度/定義s of SayHi and SayHello, instead of the longwinded....
writeln;
writeln('===============');
... we now just have...
separator;
There's more to using 手続きs than you might 心配する from this 簡潔な/要約する and 限られた/立憲的な introduction. They are important because they 簡単にする keeping a 事業/計画(する) under 支配(する)/統制する. We'll 調査する them その上の in 未来 tutorials.
|
|
Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.
....... P a g e . . . E n d s .....