このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Pascalite Programming: Fifth tutorial- plt1ef HOME - - - - - - - - - Other 構成要素 for programmers - - - - - - - - - Pascalite Tutorial (米)棚上げする/(英)提議する of Contents

Pascal Programming: A Little Counting in Binary

This 見解/翻訳/版 of this tutorial is 罰金 tuned for the open source FPC, aka 解放する/自由な Pascal. Most of what you read here should also 直接/まっすぐに 適用する if you are using Borland's Turbo Pascal (TP hereafter). It is also 利用できる for 解放する/自由な. Please send me an email with "(民事の)告訴s" if something doesn't work!

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 (人が)群がる.


Have you felt that some of the tutorials to date took things a bit 平易な? Not enough "meat" to "chew" on? 恐れる not! This tutorial has lots for you to struggle with...

We do more with "Repeat... Until" 宙返り飛行s, we nest them, we 会合,会う "Val", "無作為の", "Randomize".. all 公正に/かなり simple things... and then we go on and 会合,会う the very powerful "For... (some variable):=(something) to (something) do..." 宙返り飛行 creator. That is an important 概念. Happily, we're only having a simple "first 会合" here.

Enjoy!....

One 見解(をとる) of programming says that it is all about three simple things:

In our programs to date our input has gone in 経由で the keyboard. The program "asks" for our input when it gets to a readln line. It 蓄える/店s what we say in a variable.

に引き続いて the dictates of the 指示/教授/教育s 供給するd by the programmer, the computer "digests" the inputs. This is the "過程ing" element, and it leads to....

Some 肉親,親類d of message 存在 PUT OUT from the computer. This is the 生産(高). The place that message will go will, for us, be the computer's 審査する. People に引き続いて the Pascalite variant of these tutorials can 令状 programs which sent their 生産(高) either to a rather small, 限られた/立憲的な, 審査する, or to some LEDs. Turning an LED on (or off) is "生産(高)" just as much as words or numbers on a 審査する are "生産(高)". The printer is another 一般的に used medium for 生産(高). With a little more work, the program's 生産(高) can 影響する/感情 a wide 範囲 of actuators, from 音声部の (衆議院の)議長s to モーターs to... (there are lots of ways to do 生産(高)!)

In these introductory 一時期/支部s of this my Pascal tutorial, we will only 生産(高) things to the 審査する. Learning enough to have your computer turn LEDs on and off is not difficult... it just 要求するs that you have a PC 利用できる which you could 耐える 損失ing in your 早期に days as an electronics engineer!

Sticking (mostly) with the familiar, enter the に引き続いて program, enter what follows, and try running it, even though it is pretty pointless so far!
program Fifth;
uses crt;

var bDataIn, bErrCode:byte;
    sTmp,sDataOut:string;

begin
ClrScr;

repeat
  writeln('Enter a number, 0-7, or, to やめる, 99');

  repeat //**1
    readln(sTmp);
    val(sTmp, bDataIn, bErrCode);
  until bErrCode=0;//**2

until bDataIn=99;

writeln;//原因(となる)s a blank line in the 生産(高).
writeln('Bye.');
writeln('圧力(をかける) the "Enter" 重要な to end the program.');
readln;
end.

I hope that most of that made "sense"... of a sort? I hope you could see what would happen, even though why you'd want such a program is probably still obscure.

Let's talk in 詳細(に述べる) about the 構成要素 between the inner "repeat" (at //**1) and it's "until" (at //**2)

readln(sTmp) should not perplex you. It just fetches whatever you type (the input), and 蓄える/店s it in the variable sTmp. Because sTmp is a string type variable, you can type anything, without problems.

However, for what I want this program to do, a number is necessary. "val" is a reserved word. It is built into FPC. After "val" (for "value"), there will always be 3 parameters, in brackets.

The first will "配達する" a string to val. If I type the string "123", to you and me it looks just like the number 123. The computer isn't that "clever". Val takes what's in the string, sTmp in the 事例/患者 of our program, and 試みる/企てるs to turn it into a number. If sTmp had been 蓄える/店ing "123" when Val was called, Val would 後継する, and it would put the number 123 into the variable bDataIn. (It uses whatever variable is 供給(する)d as the second "thing" (parameter) after the Val.)

The third parameter would be filled with 0 if sTmp was "123". If Val has not been able to 変える the string into a number, it will put a 非,不,無-無 number into the third parameter, bErrCode in this 事例/患者.

Run the program. Try entering some numbers (other than 99) and some 非,不,無-numbers. I hope that you now see what the program is doing. If you enter a 非,不,無-number, you have to 供給(する) a new datum. You are "stuck" inside that inner 宙返り飛行 until you 供給(する) a number.

Okay... now 供給(する) "99". The program should 出口, after you 圧力(をかける) enter to 認める the "Bye" (program ending 警告 message). (That "99" is a "rogue value", by the way. In a moment, we're going to do "利益/興味ing" things with numbers entered by 使用者s... but "99" will be taken as a "special code", not 扱う/治療するd as just another number. It will continue to stand for "end program now." Such things are called rogue values.)

Onward! Let's make the program do something with the number. We've seen "input", and we've seen "過程ing" (井戸/弁護士席, the 影響 of 過程ing)... but the "生産(高)" has been pretty uninspired so far!

Take another small step 今後 by 修正するing the program by 追加するing the 3 lines 示すd with //**s. (Small steps work 井戸/弁護士席... when something goes wrong, you don't have far to search for a 犯人.)

program Fifth;
uses crt;

var bDataIn, bErrCode:byte;
    sTmp,sDataOut:string;

begin
ClrScr;

repeat
  writeln('Enter a number, 0-7, or, to やめる, 99');
 repeat //**
  repeat
    readln(sTmp);
    val(sTmp, bDataIn, bErrCode);
  until bErrCode=0;
 until (bDataIn<8) or (bDataIn=99);//**
writeln('Something good goes here in a moment.');//**
until bDataIn=99;
writeln;
writeln('Bye.');
writeln('Press the "Enter" key to end the program.');
readln;
end.

Now, in place of the one line....

writeln('Something good goes here in a moment.');//**

... 挿入する...

if bDataIn=0 then writeln('In binary, that would be: 000');
if bDataIn=1 then writeln('In binary, that would be: 001');
if bDataIn=2 then writeln('In binary, that would be: 010');
if bDataIn=3 then writeln('In binary, that would be: 011');
if bDataIn=4 then writeln('In binary, that would be: 100');
if bDataIn=5 then writeln('In binary, that would be: 101');
if bDataIn=6 then writeln('In binary, that would be: 110');
if bDataIn=7 then writeln('In binary, that would be: 111');

(Remember that you can copy things from here, and used Edit|Paste From Windows within FPC.)

Yes... there are more clever ways to 達成する the result... but we'll come to then. Be it ever so 天然のまま, we now have a program which will tell you the binary form of any number from 無 to seven. You INPUT a number, the program PROCESSES it, and you get the binary 同等(の) OUTPUT.

This tutorial was adapted from one for the Pascalite. The Pascalite has some 金物類/武器類 that made it possible to 令状 a more fun program for it, but what we have here for the FPC and TP Pascal compilers is just as 教育の as what was done with the Pascalite.

Did you notice the new data type you 遭遇(する)d, "byte"? Byte-type variables can 持つ/拘留する the whole numbers from 0-255 (inclusive.) They aren't very clever... but then, we didn't need anything clever here, did we?

現実に, that little bit of "cleverness" wasn't clever. Val is 有能な of 変えるing, say, the string "345" into the number 345... but a byte-type variable can't 蓄える/店 it. If you enter 345 into the program as it now stands, you'll see it come to a 衝突,墜落ing 停止(させる) when Val tries to put 345 into bTmp. You get a cryptic error message.

The 権利 way to 直す/買収する,八百長をする this would be to go 支援する and change every 言及/関連 to bDataOut to iDataOut, and 宣言する it as an integer.

A messy "quick 直す/買収する,八百長をする" would be to make the inner Repeat... Until do....

    readln(sTmp);
    bErrCode:=1;
    if length(sTmp)<3 then val(sTmp, bDataIn, bErrCode);

Notice that we 追加するd the bErrCode:=1; line? That became necessary because we will now not やむを得ず be 遂行する/発効させるing the val 声明, will we? And that could give rise to 遭遇(する)ing "until bErrCode=0" before any value has been 割り当てるd to bErrCode... Not 許すd! So we initialize the variable, just in 事例/患者.

That brings us to the end of the heart of this tutorial. There are two other things to を取り引きする in a moment, but take a moment to catch your breath here.




Once again, we're about to 遭遇(する) something that was more fun on the Pascalite. With that, we could wink LEDs in pretty patterns. With FPC and TP, you can do much, much more... but for the moment they'll look dull. Sorry.

改訂する (or 取って代わる) the program we had to make it...

program Fifth;
uses crt;

var bDataIn, bErrCode, bCount:byte;
    sTmp,sDataOut:string;

begin
ClrScr;
bCount:=0;
randomize;
repeat
  bCount:=bCount+1;
  bDataIn:=無作為の(4);
  if bDataIn=0 then writeln('In binary, that would be: 000');
  if bDataIn=1 then writeln('In binary, that would be: 001');
  if bDataIn=2 then writeln('In binary, that would be: 010');
  if bDataIn=3 then writeln('In binary, that would be: 011');
  if bDataIn=4 then writeln('In binary, that would be: 100');
  if bDataIn=5 then writeln('In binary, that would be: 101');
  if bDataIn=6 then writeln('In binary, that would be: 110');
  if bDataIn=7 then writeln('In binary, that would be: 111');
  writeln('圧力(をかける) the Enter 重要な');
  readln;
until bCount=12;
writeln;
writeln('Bye.');
writeln('圧力(をかける) the "Enter" 重要な to end the program.');
readln;
end.

What we have is much like our earlier program. However, now instead of a human 供給(する)ing numbers, the computer is doing it. We've also changed the program so that it does 12 numbers and then stops... the rogue value 機械装置 has been taken out. Because humans aren't inputting things, we can take out a bunch of 実験(する)s.

The "無作為の" "thing" is new. What happens when you say bDataIn:=無作為の(8) is that the computer 選ぶs a number for you, as if it has thrown dice. The number it returns could be a 無, or anything up to a seven, inclusive. It won't be an 8. If you 手配中の,お尋ね者 0- 15, inclusive, you'd say 無作為の(16).

Notice the line 説 "randomize"? You have to 遂行する/発効させる "randomize" once, and preferably only once, as here, to get different 無作為の numbers each time you run the program. (Yes, I realize that Pascal's idea of "無作為の" isn't やめる what most people mean by "無作為の".... but it does very nicely for many things.




One last thing... not small, I'm afraid... don't skip this next stuff!

Redo the program again. Make it....

program Fifth;
uses crt;

var bDataIn, bErrCode:byte;
    sTmp,sDataOut:string;

begin
ClrScr;
randomize;
for bDataIn:=0 to 7 do begin
  if bDataIn=0 then writeln('In binary, that would be: 000');
  if bDataIn=1 then writeln('In binary, that would be: 001');
  if bDataIn=2 then writeln('In binary, that would be: 010');
  if bDataIn=3 then writeln('In binary, that would be: 011');
  if bDataIn=4 then writeln('In binary, that would be: 100');
  if bDataIn=5 then writeln('In binary, that would be: 101');
  if bDataIn=6 then writeln('In binary, that would be: 110');
  if bDataIn=7 then writeln('In binary, that would be: 111');
  writeln('圧力(をかける) the Enter 重要な');
  readln;
  end;//for 宙返り飛行
writeln;
writeln('Bye.');
writeln('圧力(をかける) the "Enter" 重要な to end the program.');
readln;
end.

This program is even simpler than the last. Of course it isn't as "clever", now, either. All it does is show you the binary for 0,1,2,3,4,5,6... and!... 7.

Notice that we've got rid of the bCount variable.

More 特に notice that we've 取って代わるd the "Repeat... Until" with a terribly important 宙返り飛行 creator, the "For" 声明. The reserved words "for" and "to" and "do" are all part of it.

The "For" 声明 starts off by putting a value in a variable, 0 in bDataIn in this 事例/患者. It then, for the moment, skips over the "to 7" bit. The word "Do" always appears where you see it. The "For" then 原因(となる)s whatever comes next to happen. In this 事例/患者 "whatever comes next" is やめる a lot... everything from the "Begin" 負かす/撃墜する to the "End; //For". Remember 構内/化合物 声明s? The "Begin... End" "glue" all this simple 声明s together, making what, as far as the "For" is 関心d, just "one" (big) 声明.

When the "one big 声明" has been 遂行する/発効させるd once, the computer goes 支援する to the start of the For line. It remembers that the line has already been done, and "looks" in the bDataIn variable. It 追加するs 1 to whatever it finds. At the moment, it would find a 0, so after 追加するing one, there's a one. That is put 支援する into the bDataIn variable. Next the computer looks at the "to 7" part of the "For" 声明. It compares the contents of bDataIn to the 7. As bDataIn is not yet larger than 7, the whole thing repeats... the "one big 声明" is 遂行する/発効させるd again, and the computer goes 支援する to the start of the "For" line.

This is repeated again and again... but 結局, the number in bDataIn is bigger than 7. At this point, the computer skips over the "one big 声明, and goes on to do whatever comes after it. And from there it just carries on.

The repeat... until 宙返り飛行 has its uses. But the "For" 宙返り飛行 probably gets used more.

If that wasn't 100% (疑いを)晴らす, don't worry... you'll 会合,会う the "For" 宙返り飛行 many more times!




Enough for now, I 信用? There's always the 索引 of Pascal tutorials when you're raring for more.


Please also 公式文書,認める that I have two other 場所/位置s, and that the に引き続いて search will not 含む them. They have their own search buttons.

My Sheepdog Guides 場所/位置.
My Arunet 場所/位置.

Go to the 場所/位置s above, and use their search buttons if you want to search them.
To search this 場所/位置....

Search this 場所/位置 or the web 力/強力にするd by FreeFind

場所/位置 search Web search
The search engine 単に looks for the words you type, so....
*    (一定の)期間 them 適切に.
*    Don't bother with "How do I get rich?" That will 単に return pages with "how", "do", "I"....

You can also search this 場所/位置 without using forms.
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.


Want a 場所/位置 hosted, or email? You can also help me if you 調印する up 経由で this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their 顧客s. The Google advertisers 支払う/賃金 me. I know nothing about them or their services, of course.)



Valid HTML 4.01 Transitional Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!


Why does this page 原因(となる) a script to run? Because of the Google パネル盤s, and the code for the search button. Also, I have some of my pages' traffic 監視するd for me by eXTReMe tracker. They 申し込む/申し出 a 解放する/自由な tracker. If you want to try one, check out their 場所/位置. Why do I について言及する the script? Be sure you know all you need to about spyware.
Editor's Main Homepage
How to email or 令状 this page's editor, Tom Boyd

....... P a g e . . . E n d s .....