Recent

Author Topic: While loop and two-dimensional array  (Read 6165 times)

PG_97

  • Newbie
  • Posts: 3
While loop and two-dimensional array
« on: January 21, 2021, 09:02:49 am »
Good morning,

I am trying to loop through a 2 dimensional array with a while loop. But somehow I can't figure out how to do it.
Of course you can go through the whole thing with a for loop, but then I would have to include too many terminations. Altogether 4 pieces in a loop.

The program should check a quadrilateral, if it belongs to the magic quadrilaterals and the procedure with which I check it I want to go through with a while loop.

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: While loop and two-dimensional array
« Reply #1 on: January 21, 2021, 09:15:24 am »

Code: Pascal  [Select][+][-]
  1. var
  2.     arr: array of array of integer;
  3.     i, j: integer;
  4. begin
  5.     i:= Low(arr);
  6.    while i <= High(arr) do begin
  7.         // .......................
  8.         j := Low(arr[i]);
  9.         while j <= High(arr[i]) do begin
  10.                 // .........
  11.                j += 1;
  12.         end;
  13.         i += 1;
  14.    end;
  15. end;
  16.  
   
 
« Last Edit: January 22, 2021, 02:47:26 am by egsuh »

PG_97

  • Newbie
  • Posts: 3
Re: While loop and two-dimensional array
« Reply #2 on: January 21, 2021, 09:38:09 am »
Thank you very much @egsuh.
This is a very nice code from you.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: While loop and two-dimensional array
« Reply #3 on: January 21, 2021, 10:41:29 am »
This is a perfect example of why one should use code tags>:D
This is what egsuh really meant:

Code: Pascal  [Select][+][-]
  1. var
  2.     arr: array of array of integer;
  3.     i, j: integer;
  4. begin
  5.     i:= Low(arr);
  6.    while i <= High(arr) do begin
  7.         // .......................
  8.         j := Low(arr[i]);
  9.         while j <= High(arr[i]) do begin
  10.                 // .........
  11.                j += 1;
  12.         end;
  13.         i += 1;
  14.    end;
  15. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: While loop and two-dimensional array
« Reply #4 on: January 21, 2021, 11:09:16 am »
This is a perfect example of why one should use code tags>:D

Seconded. @egsuh please look at your code as displayed by the forum software, and note how some of the subscripts have mysteriously vanished.

Where I come from there's a good-natured tradition of "eBeers" for people who have helped the community, please consider yourself the recipient of a eKick: you should know better by now :-)

MarkMLl

MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: While loop and two-dimensional array
« Reply #5 on: January 21, 2021, 11:37:03 am »
OMG

Why the indexes of i and j are gone?  .. Bracket i seems to be interpreted as meaning italic.
Actually I prefer not to use code tags, because normal text is easier to read, unless the code is rather long. Sorry for that. I'll put all codes within code tags.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: While loop and two-dimensional array
« Reply #6 on: January 21, 2021, 11:57:07 am »
OMG

Why the indexes of i and j are gone?  .. Bracket i seems to be interpreted as meaning italic.

BECAUSE YOU DIDN'T TAG IT AS CODE!!!!!

Quote
Actually I prefer not to use code tags, because normal text is easier to read, unless the code is rather long. Sorry for that. I'll put all codes within code tags.

I'm sorry, but preferences don't come into it here. If you don't tag stuff as code some (but not all) of your stuff in (square) brackets will be misinterpreted, and that will quite simply cause problems that the rest of us have to sort out.

There's obviously also the issue of monospaced founts being preferred for code and command line examples, in part because they're usually designed to be "programmer friendly" so distinguish better between parentheses and braces etc.

Look, I've been using this sort of discussion software for 30+ years starting off with "Forum" on Multics at Lowbrow. I habitually use older conventions to represent /italics/ etc., but if it caused significant grief I'd get my arse in gear and stop. But seriously, the two tags that matter are code=pascal and tt... please assume the existence of the brackets there because by now you should be able to appreciate that actually putting them into flowing text is a hassle.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: While loop and two-dimensional array
« Reply #7 on: January 21, 2021, 04:16:56 pm »
egsuh, if you really, really hate code tags that much another posibility is to use [nobbc] tags, which would result in:
var
    arr: array of array of integer;
    i, j: integer;
begin
    i:= Low(arr);
   while i <= High(arr) do begin
        // .......................
        j := Low(arr[i]);
        while j <= High(arr[i]) do begin
                // .........
               j += 1;
        end;
        i += 1;
   end;
end;

Though, since you've to use tags anyway, why not [code]? ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: While loop and two-dimensional array
« Reply #8 on: January 21, 2021, 04:30:59 pm »
I wonder why posters do not read their text any more after they had pressed the "Post" button. Even without reading I would wonder why my text suddenly is italic, and I would investigate. Or sometimes I see that the entire text is displayed as a quote - because maybe the end-quote tag is misspelled. Why don't posters see this and react? Every user is allowed to edit his own posts. So what is the problem?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: While loop and two-dimensional array
« Reply #9 on: January 21, 2021, 04:47:27 pm »
I wonder why posters do not read their text any more after they had pressed the "Post" button.

I do wonder instead that so few people seems to be aware of the "Preview" button ... ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: While loop and two-dimensional array
« Reply #10 on: January 21, 2021, 05:25:49 pm »
I do wonder instead that so few people seems to be aware of the "Preview" button ... ;)

I'm tempted to say that it's humility, with people being reluctant to gloat over the bon mots that they've inflicted on the community >:-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: While loop and two-dimensional array
« Reply #11 on: January 21, 2021, 06:08:38 pm »
Why the indexes of i and j are gone?  .. Bracket i seems to be interpreted as meaning italic.
BECAUSE YOU DIDN'T TAG IT AS CODE!!!!!
+1
And even better without them at all:
Code: Pascal  [Select][+][-]
  1. type
  2.   TOneDimensionArray = array of Integer;
  3.   TTwoDimensionArray = array of TOneDimensionArray;
  4. var
  5.   Arr: TTwoDimensionArray;
  6.   VArray: TOneDimensionArray;
  7.   Value: Integer;
  8. begin
  9.   for VArray in Arr do
  10.   begin
  11.     for Value in VArray do
  12.     begin
  13.         // ...
  14.     end;
  15.   end;
  16. end;

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: While loop and two-dimensional array
« Reply #12 on: January 21, 2021, 06:24:30 pm »
Actually I prefer not to use code tags, because normal text is easier to read, unless the code is rather long. Sorry for that. I'll put all codes within code tags.

Please note that most people think different about the readability. For that reason it is customary on the forum to use code tags.

Most browser allow to resize them, to display the entire code without scrolling (so long as you do not have super long lines).
Most browser will also "copy and paste" the code without the line numbers. So people who want to copy the code to their IDE can do that.



egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: While loop and two-dimensional array
« Reply #13 on: January 22, 2021, 03:01:45 am »
I apologize for troubles caused. 

Normally I preview and check what I wrote, but in this case, I left my place as soon as finishing typing my first post in.  I did not realize some texts are missing or displayed in italics.

Later I saw Lucamar's comment and found out that the post is not displayed as I wanted, but I did not change my text because there were "corrected" one, and thought the issue is over --- not to insist my preference of style at public place.

Sorry for the confusions again.

mischi

  • Full Member
  • ***
  • Posts: 170
Re: While loop and two-dimensional array
« Reply #14 on: January 22, 2021, 10:19:57 am »
Am i the only one, who does not like the general "sound" of replies here? Is it a such an effort to answer with some more politeness and friendliness? I would understand that a first time poster would never come back and I do not accept the point, that this is his/her problem.

 

TinyPortal © 2005-2018