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

翻訳前ページへ


Arrays in Pascalite Programming- plt1gp HOME - - - - - - - - - Other 構成要素 for programmers - - - - - - - - - Pascalite Tutorial (米)棚上げする/(英)提議する of Contents

Pascalite Programming: Arrays

This 見解/翻訳/版 of this tutorial is 罰金 tuned for a Pascalite, or the 解放する/自由な ソフトウェア Pascalite emulation. Please send me an email with "(民事の)告訴s" if something doesn't work!

If you have the open source FPC, aka 解放する/自由な Pascal or Borland's Turbo Pascal (TP hereafter), then there's a separate tutorial for you, covering much of the ground as 現在のd here for the Pascalite (人が)群がる.



A special place to keep things: Arrays

Be sure to look at the previous tutorial before 試みる/企てるing this one. In it we looked at using a computer to 記録,記録的な/記録する the activity of a hamster. The "For... To... Do..." 声明 was introduced. In this tutorial we are also going to 跡をつける some events, and will 会合,会う arrays for the first time. They are a special type of data, or a special sort of variable, if you prefer to think of them that way.

In this 見解/翻訳/版 of the hamster 監視する, we're going to 延長する it to 監視する four hamsters!

This might have left for "Level 2" of the tutorials, but it introduces a 根底となる programming 道具: arrays.

We've already looked at simple variables. They 許す us to keep things so that we can 言及する to them. Now we're moving on to arrays. Like a simple variable, they are a place for keeping something. In 新規加入 to the 特徴 of a simple variable, they 許す us extra ways, clever ways, to 明示する which piece of (警察などへの)密告,告訴(状) we want. Type in the に引き続いて. Notice there is lots of 範囲 for using copy/ paste to 減少(する) typing and 増加する 正確. You'll need to be careful to distinguish 無s and ohs... boB0Was is bee oh (for Boolean) bee 無 (for the first element of port B).

Don't let the blank lines 混乱させる you... You can always put them in where ever you want to ーするために help make 論理(学)の 封鎖するs of the program show up. The indenting is there for the same 推論する/理由.

program FourHamsters;

var boB0Was,boB1Was,boB2Was,boB3Was: boolean;
      bTurns:array [0..3]of byte;

begin
def_out(d0,d1,d2,d3,d4,d5,d6,d6,d7);

bTurns[0]:=0;{Put 無 in each of the 反対するs}
bTurns[1]:=0;
bTurns[2]:=0;
bTurns[3]:=0;

boB0Was:=b0; {Find out what the switches are 始める,決める to so far}
boB1Was:=b1;
boB2Was:=b2;
boB3Was:=b3;

repeat

if not(b0) then boB0Was:=誤った;
if not(boB0Was) and b0 then begin
     bTurns[0]:=bTurns[0]+1;
     boB0Was:=true;
     end;

if not(b1) then boB1Was:=誤った;
if not(boB1Was) and b1 then begin
     bTurns[1]:=bTurns[1]+1;
     boB1Was:=true;
     end;

if not(b2) then boB2Was:=誤った;
if not(boB2Was) and b2 then begin
     bTurns[2]:=bTurns[2]+1;
     boB2Was:=true;
     end;

if not(b3) then boB3Was:=誤った;
if not(boB3Was) and b3 then begin
     bTurns[3]:=bTurns[3]+1;
     boB3Was:=true;
     end;

until 4=5;
end.

The program so far will watch switches b0, b1, b2, and b3. It will count how many times each one is turned on. It won't yet 陳列する,発揮する how many times each one is turned on, though.

On an ordinary PC, it would be no problem to show four numbers on the 審査する. (one for the number of times each switch was turned on). However, without using the LCD 審査する, showing four numbers on a Pascalite would be hard. To get around this, I've decided to design the program as follows: d0, d1, d2... d7 will show a number in binary, as in the first way of showing answers in the previous tutorial. WHICH number it shows will depend on the setting of switches a0, a1, a2 and a3. It will be up to the 使用者 to remember that only one of these four switches may be turned on at any time. (In a 商業の 製品 a better 解答 would have to be 器具/実施するd, but the extra code wouldn't have any value to the 目的 of this tutorial). The program will "work" even if you do have more than one of the 反対する 選択 switches on... you should be able to see what it will do when, say, switches a2 and a3 are on. It that instance, the count of b3 "ons" will be 陳列する,発揮するd, won't it... which shouldn't be 許すd to be possible, given that the 使用者 might just have most recently turned a2 on, and thus might be thinking they're looking at the count of a2 "ons".

To 供給する for the 生産(高) of the count, and 選択 thereof, just 追加する the に引き続いて. Again: make use of copy/ paste if you know how to.. but it isn't 必須の if you don't.

if a0 then 令状(portd,bTurns[0]);
if a1 then 令状(portd,bTurns[1]);
if a2 then 令状(portd,bTurns[2]);
if a3 then 令状(portd,bTurns[3]);

Run the program again. 警告: While the program would run just as you would 推定する/予想する it to on a real Pascalite, the 解放する/自由な 事実上の Pascalite and the simulator that comes with it runs more slowly than you can switch the 事実上の switches on and off. Because the program is getting 比較して big, it will appear to fail to count some "on"s unless you switch on and off やめる slowly. Be sure to 始める,決める the simulator to run at its 最高の,を越す 速度(を上げる), and wait at least 2 seconds between switchings, if you want to be fully 安全な.

So. Now we have a program using the array bTurns. bTurns 供給するs four places to 蓄える/店 a byte. A particular one of them, say bTurns[2], is called an element of the array. In the program in the tutorial we 港/避難所't taken advantage of the 力/強力にする of arrays... we could have done what we've done so far with four variables 指名するd bTurns0, bTurns1, bTurns2 and bTurns3. For a very modest example of the 力/強力にする of arrays, let's go 支援する to the part of the program that starts each element of bTurns off at 無. We had....

bTurns[0]:=0;
bTurns[1]:=0;
bTurns[2]:=0;
bTurns[3]:=0;

After we 追加する c1 to the variables 宣言, we can 取って代わる those lines with:

for c1:=0 to 3 do bTurns[c1]:=0;

Look at that closely; make sure you see what it's doing, why it 達成するs the same thing that the previous answer 達成するd. It may not see very impressive. However, consider what an 改良 it would be if 150 bTurns elements had to be initialized! And there are more subtle things that you can do which can only be done through the 力/強力にする of arrays.

And so to bed! Unless you want to go 支援する to the (米)棚上げする/(英)提議する of contents for another one? :-)




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 .....