このページは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 (人が)群がる.
The Pascalite, while having a more 限られた/立憲的な 見解/翻訳/版 of the language, is blessed with some special 金物類/武器類 advantages. A few of the tutorials at the start of the series depend やめる ひどく on those features. When you read the 残り/休憩(する) of this tutorial, you may notice where things got a bit 緊張するd as I tried to cover the same ground in a FPC/ TP 環境. Sorry! Still 価値(がある) what you're 支払う/賃金ing?
Although this tutorial starts weakly, it 現実に ends more 堅固に than the tutorial it derives from. Swings and roundabouts. Life.
Enter the に引き続いて, or create it from the program created during the previous tutorial. It is very nearly the same code. I've changed the program 指名する, 追加するd the lines at //**1 and //**2, and わずかに changed the line at //**3. And yes, this code could be 改善するd, and yes, the changes are trivial in 影響. They do show you something new, though, which also has 非,不,無-trivial uses!
program Fourth; uses crt; var sItWas, sLatest:string; iCount:integer; boMatch:boolean; //** 1 begin ClrScr; iCount:=0; writeln('Type a short word, then 圧力(をかける) the "Enter" 重要な.'); writeln('This will 始める,決める the password to be matched later.'); readln(sItWas); ClrScr; repeat iCount:=iCount+1; writeln('You have gone through the 宙返り飛行 ',iCount,' times.'); writeln('Type the password again to leave this 宙返り飛行, or'); writeln('type something else. In either 事例/患者, then'); writeln('圧力(をかける) the "Enter" 重要な'); readln(sLatest); if sLatest=sItWas then boMatch:=true //no ; here else boMatch:=誤った; //** 2 if sLatest=sItWas then writeln('Bye') //no ; here else writeln('No, that was not the password.'); writeln;//this 原因(となる)s a blank line. until (boMatch) or (iCount>5);//** 3 writeln('圧力(をかける) the "Enter" 重要な to end the program.'); readln; end.
First a simple 事柄: The variable 指名するs. You could call them 刑事 and Jane. But it is better to use 指名するs that mean something. The "bo" prefix doesn't MAKE the variables Boolean... the var 声明 does that... but if you use such variable 指名する prefixes, it will help you remember what the variables are 存在 used for. I 普通は prefix variables of type string with an s which is why, in the previous program, I used sItIs and sItWas as the 指名するs.
Let's look at the 新規加入s and the change....
//** 1: This creates, "宣言するs", the boolean variable we're going to use. Always 宣言する a variable before you use it.
//** 2: This new "if... then... else..." 声明 割り当てるs a value to boMatch, depending on what is on sLatest and sItWas. If the contents of those variables match, then boMatch is true after this 声明 has 遂行する/発効させるd. See how sensible variable 指名するs make your code 平易な to follow? Choose your variable 指名するs accordingly.
In a previous tutorial, we said that it is important to initialize variables. You may have wondered why there wasn't a "boMatch:=true;" (or maybe ":=誤った") before the repeat 宙返り飛行. Look at the code. boMatch will always have something put into it during line //**2's 死刑執行. And we never try to 協議する what is in boMatch until line //** has 遂行する/発効させるd at least once. boMatch is initialized the first time we pass through //**2, and that is soon enough.
//** 3: In this line, we've 取って代わるd the 条件 "sLatest=sItWas" with "boMatch". It is, as you may realize, a very trivial 交替/補充. But is all this (疑いを)晴らす to novices in my readership? When the program comes across "sLatest=sItWas", the computer goes off and "looks" at what's in sLatest, and what's in sItWas, and compares them, in the place of 条件, one is left with the 同等(の) of a "true" or of a "誤った". A programming text might (やめる 適切に) say that "sLatest=sItWas" returns a Boolean value, with something drawn from the 名簿(に載せる)/表(にあげる) of possible values for a Boolean type datum, i.e. "true" or "誤った".
The idea of "boiling things 負かす/撃墜する", of something "returning" something is important. It lets you look at a program at different levels. いつかs you need to concentrate on 詳細(に述べる); いつかs on the broader picture. In the program above, いつかs you need to look at the 詳細(に述べる) of what makes boMatch true or 誤った. You do that by looking in the if... then... else... 声明. At other times, you're more worried about what happens when there was a match, as in the line "until (boMatch) or..."
The 比較して trivial move of the 実験(する) of "if sLatest=sItWas", and the 蓄える/店ing of the result in boMatch, is one of those things that arose from making this tutorial derive nicely from the older Pascalite tutorial. But the code is perfectly valid, perfectly 訂正する... and not unlike something that you might 遭遇(する) in other, いっそう少なく trivial, circumstances. We'll come 支援する to this later.
That takes care of a lot of things. Now to 演説(する)/住所 a few loose ends. In general, it is best to read these tutorials with your browser not filling your 審査する, and adjusted to make a comfortably 狭くする column of text. You may need to 広げる it a bit to see all of every line of the code which is coming up.
Surely you thought that....
if sLatest=sItWas then boMatch:=true //no ; here else boMatch:=誤った; if sLatest=sItWas then writeln('Bye') //no ; here else writeln('No, that was not the password.');
was dreadfully messy? You were 権利! And Pascal code doesn't need to be, and shouldn't be, messy. In an earlier tutorial, we talked a little about nested "begin... end" 封鎖するs.
An "if... then ... else... " 声明, as used to date, needs "things" plugged in where I've put "...". The first "thing", as you know, must be a 条件, something that returns, boils 負かす/撃墜する to, "true" or "誤った".
After the "then" and after the "else" we have, to date, put simple 声明s, e.g. "boMatch:=true"
If you "包む" several simple 声明s up in a "begin... end" 封鎖する, they become, 効果的に, "one" 声明. They "boil 負かす/撃墜する to" "one" 声明. (That "boil 負かす/撃墜する to idea again!)
When you "包む" 声明s together thus, you put a semicolon between each. I think of it as "glue". This is just a 延長/続編 of the general use of the semicolon at other levels of the program's editing. 公式文書,認める: "if... then... else" is ONE, SIMPLE 声明. That's why there are no semicolons in it, say just before the else, which is a tempting place to put one.
The に引き続いて is 同等(の) to what we had before, and a form you will come to see as neater. I would guess it looks neater to you even now when it is unfamiliar?
if sLatest=sItWas then begin boMatch:=true; writeln('Bye');//**1 end;//no ; here //**2 else begin boMatch:=誤った; writeln('No, that was not the password.');//**3 end;//else **4
(I've 誇張するd the indenting, to make my point.)
We still have "if... then... else...". Look at the code carefully; be sure that you see that.
The "//no ; here" that I've put on line //**2 is something that I routinely put in my code. If in 疑問, put semicolons in... they often do no 害(を与える), but a semicolon before an else is always bad news.
厳密に speaking, you don't need the semicolons at //**2 and //**3, but I would put them in.
You don't need them, because they would be to "glue" another simple 声明 into the 構内/化合物 声明 between the "begin" and "end". The word "end" tells the compiler that the "begin... end" 封鎖する ends here. A semicolon after the last 声明 before the "end" 簡単に "glues" a "do nothing" 声明 の上に the 構内/化合物 声明 between the "begin" and "end".
I would put those semicolons in, because it is やめる ありふれた to go 支援する and 追加する other things to the 構内/化合物 声明, and if you didn't put the semicolon in when you wrote what was there before, you may 井戸/弁護士席 fail to do so when you 追加する the new line.
Moving on with "begin... end": Be very careful that every "begin" is matched by an "end".
Once you start using the "begin... end" "trick" to make a number of simple 声明s behave as one 声明 (it's called a 構内/化合物 声明), be careful to remember the "begin" and "end" around the simple 声明s. It is やめる 平易な to 令状 the に引き続いて when you meant the code most recently 現在のd....
if sLatest=sItWas then begin boMatch:=true; writeln('Bye'); end;//no ; here else boMatch:=誤った; writeln('No, that was not the password.');
The "then" part is 不変の, but look at what is supposed to happen in the "else" 状況/情勢.
始める,決める out like that, the error is 公正に/かなり 平易な to see... another 推論する/理由 for setting things out like that... but I 保証する you: You will いつか spend a few hours 跡をつけるing 負かす/撃墜する a mistake like that. Like what? I'm going to explain...
With the 欠陥のある code, instead of the "writeln('No, that was not the password.');" happening only when sLatest does not equal sItWas, it will happen every time. It has become the first 声明 after the "if... then... else..." The "..." part for the "else" is now 簡単に "boMatch:=誤った;"
信用 me: Be careful with your "begin... end" pairs.
Moving on again: One way to help yourself 避ける errors is, when entering code, to type both the "begin" and the "end", and then go 支援する and fill in what they are "gluing" into a 選び出す/独身 構内/化合物 声明.
I.e., I would have entered the code you see above in the に引き続いて steps....
if sLatest=sItWas then begin end;//no ; here else begin end;//else
... followed by....
if sLatest=sItWas then begin boMatch:=true; writeln('Bye'); end;//no ; here else begin end;//else
... and then I would have entered the stuff between the "else"s "begin... end".
Take a 深い breath. Make sure you're (疑いを)晴らす on the above. I'm about to go on to a 関係のある topic.
Ready? Okay....
You've already seen something rather like the "begin... end" 封鎖する. I'll leave a big vertical blank space so you can think "What could that be?" before seeing the answer.
... answer その上の 負かす/撃墜する page...
... answer その上の 負かす/撃墜する page...
Answer: The "repeat... until" 封鎖する is like the "begin.. end" 封鎖する, in that it can "glues" a bunch of stuff together into a "選び出す/独身" "thing".
The "repeat... until" 封鎖する is わずかに "fancier" that the "begin... end" 封鎖する. (You may go through the 封鎖する more than once, which you won't do with a "begin... end" unless there is something outside of it 原因(となる)ing the repetition.) However, just like "begin... end", the words "repeat... until" will have one or more 声明s between them. (A "begin... end" 封鎖する with only one simple 声明 in it would be pointless.... but it would work.) If there is more than one simple 声明 in the 封鎖する, there should be a semicolon between each of them. Thus, 厳密に speaking, one could say that either type of 封鎖する has "one 声明" in it... either a simple 声明, or a 構内/化合物 声明 (simple 声明s "glued" together with semicolons). That bit of cleverness is not mere academic pedantry. You should try to see your program's structure in these 条件.
=====
And now for something 完全に different!
In the program we've been discussing, the boMatch variable is pretty superfluous. It could be written out with no loss of clarity.
However, what we did does いつかs have its uses, 特に in more コンビナート/複合体 programs.
Imagine a program not unlike our example program. A sketch of the important bits is as follows. N.B. What follows is not 完全にする code, it would never run....
repeat boMatch:=誤った; if (first 複雑にするd 可能性) then boMatch:true; if (second 複雑にするd 可能性) then boMatch:true; if (third 複雑にするd 可能性) then boMatch:true; if (fourth 複雑にするd 可能性) then boMatch:true; until boMatch;
... and that's the 簡単にするd code! You will get 宙返り飛行s (and other structures) with all sorts of things going on within them, with all sorts of ways for the time to leave the 宙返り飛行 to arise. What we've done above is useful: 始める,決める "boMatch" 誤った, to begin with, knowing that it can always be made true anywhere below the initialization, and thus 誘発する/引き起こす an 出口 from the 宙返り飛行, if the time has come, however arcane the 指示,表示する物 thereof, to do so.
=====
Moving on again...
This is a "捨てる" that doesn't fit the FPC/ TP tutorial very 井戸/弁護士席, but it was covering in the Pascalite tutorials at this point, so I'm shoehorning it in here, so you'll be ready for その後の things.
Forget the program we've been discussing. Consider a program about the 天候 with three boolean variables: boCold, boRaining, and boSnowing.
Starting with the very, very 平易な:
if boCold then writeln('Put a coat on.');
平易な? Yes. But 公式文書,認める two things: You don't have to say "if boCold=true...". If boCold is 持つ/拘留するing "true", then "boCold=true" boils 負かす/撃墜する to "true", so it would work. But "boCold" on it's own, when the variable boCold 持つ/拘留するs "true" also boils 負かす/撃墜する to true, and more quickly, so there's no need for the longwinded 見解/翻訳/版.
In different circumstances, you might want to say "if boCold=誤った..." which is perfectly 許容できる. Alternatively, you can say "if not boCold".
"Not" is a reserved word... it is part of the Pascal language, like "begin", "end", etc. It is a boolean 操作者. Consider, for comparison, mathematical 操作者s. There's "squared" for instance. 3 squared is 9. "x squared" boils 負かす/撃墜する to the number multiplied by itself. A boolean thing "not"ed boils 負かす/撃墜する to true if the boolean thing was 誤った, and to 誤った if the boolean thing was true.
This is usually 描写するd with a truth (米)棚上げする/(英)提議する:
"Boolean thing" NOT "Boolean thing" 誤った true true 誤ったThe 同等(の) for "squared" would be....
"Number" "Number" squared" 1 1 2 4 3 9 4 16 ... etc
Pascal would also be やめる happy with the に引き続いて...
if boRaining or boSnowing then writeln('Bring umbrella.');
"Or" is another Pascal reserved word, as is "and". They are two more boolean 操作者s. Where "not" operated on a 選び出す/独身 boolean value, "or" and "and" operate on two values, returning ("boiling 負かす/撃墜する") to a 選び出す/独身 value. Because there are two "inputs", these 操作者s are called binary 操作者s. (The 指名する has nothing to do with the fact that they are いつかs 適用するd to numbers you may be thinking of in binary form.) Can you think of some binary 操作者s used in everyday mathematics?
... answer その上の 負かす/撃墜する page...
Answer to "指名する some binary 操作者s used in everyday mathematics": 平易な! 追加するing, subtracting, multiplying, etc!
Here are the truth (米)棚上げする/(英)提議するs:
(BT= "Boolean Thing") "BT1" "BT2" BT1 AND BT2 誤った 誤った 誤った 誤った true 誤った true 誤った 誤った true true true "BT1" "BT2" BT1 OR BT2 誤った 誤った 誤った 誤った true true true 誤った true true true true
The 同等(の) for "追加するd" would be....
"Num" for "number" "1stNum" "2ndNum" 1stNum PLUS 2ndNum 0 0 0 0 1 1 0 2 2 ... snip... 9 7 16 9 8 17 9 9 18 ... etc
So far, we've looked at simple 条件s. You can get "clever"....
if (boRaining or boSnowing) and boCold then writeln('Bring umbrella and wear coat.');
公式文書,認める the use of the brackets, (), to 示す the order of 操作/手術s. Because of the brackets, you first boil 負かす/撃墜する the "boRaining or boSnowing" to a "true" or a "誤った". You then "and" that with what's held in boCold to get the final "answer" to whether you do the "then" part or not.
N.B. You will often 令状 条件s like "iCount>5". (We had that as part of our program. Revisit the text さらに先に up the page, if you are 不明瞭な about this.) If you have one of those in a 構内/化合物 条件, put it in brackets. Also put anything with an equals 調印する in it in brackets, e.g.
if (iCount=5) and (boRaining=誤った) then...
Without the brackets, Pascal いつかs does 予期しない things, like trying to 扱う/治療する the foregoing as....
if iCount=(5 and boRaining)...
Just before we end, I'm going to give you one more Boolean 操作者, just to 一連の会議、交渉/完成する out the story....
The Boolean 操作者 "xor" was 指名するd from the words "排除的 or". It is a special 事例/患者 of the "or" 操作者. Truth (米)棚上げする/(英)提議する....
(BT= "Boolean Thing") "BT1" "BT2" BT1 XOR BT2 誤った 誤った 誤った 誤った true true true 誤った true true true FALSE
When you use the ordinary "or" to 連合させる two boolean things, the result, the boiled 負かす/撃墜する 選び出す/独身 Boolean answer is "true" if the first OR the second of the things you were ORing together were true. This 含むs the 事例/患者 where both of the inputs are true. The EXCLUSIVE "OR" 除外するs this 事例/患者. boCold xor boRaining only boils 負かす/撃墜する to "true" if boCold is true, OR if boRaining is true, but the result is FALSE (not true) if BOTH of them are true.
So! Now you know a lot more than you did! There are more tutorials for you as soon as you 回復する from this 開会/開廷/会期.
要約....
(Sorry... I'll try to 令状 one someday!)
|
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 .....