While loop and two-dimensional array lazarus / 61-Beginners ---------------------------------------------------------------------- PG_97 · 2021-01-21 08:02 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 · 2021-01-21 08:15 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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; ---------------------------------------------------------------------- PG_97 · 2021-01-21 08:38 Thank you very much @egsuh. This is a very nice code from you. ---------------------------------------------------------------------- lucamar · 2021-01-21 09:41 This is a perfect example of why one should use code tags.  This is what egsuh really meant: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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; ---------------------------------------------------------------------- MarkMLl · 2021-01-21 10:09 Quote from: lucamar on January 21, 2021, 10:41:29 amThis is a perfect example of why one should use code tags.  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 ---------------------------------------------------------------------- egsuh · 2021-01-21 10:37 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 · 2021-01-21 10:57 Quote from: egsuh on January 21, 2021, 11:37:03 amOMG 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!!!!! QuoteActually 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 ---------------------------------------------------------------------- lucamar · 2021-01-21 15:16 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]? ---------------------------------------------------------------------- wp · 2021-01-21 15:30 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 · 2021-01-21 15:47 Quote from: wp on January 21, 2021, 04:30:59 pmI 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 ... ---------------------------------------------------------------------- MarkMLl · 2021-01-21 16:25 Quote from: lucamar on January 21, 2021, 04:47:27 pmI 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 ---------------------------------------------------------------------- ASerge · 2021-01-21 17:08 Quote from: MarkMLl on January 21, 2021, 11:57:07 amQuote from: egsuh on January 21, 2021, 11:37:03 amWhy 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TOneDimensionArray = array of Integer;  TTwoDimensionArray = array of TOneDimensionArray;var  Arr: TTwoDimensionArray;  VArray: TOneDimensionArray;  Value: Integer;begin  for VArray in Arr do  begin    for Value in VArray do    begin        // ...    end;  end;end; ---------------------------------------------------------------------- Martin_fr · 2021-01-21 17:24 Quote from: egsuh on January 21, 2021, 11:37:03 amActually 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 · 2021-01-22 02:01 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 · 2021-01-22 09:19 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. ---------------------------------------------------------------------- PascalDragon · 2021-01-22 09:31 Quote from: mischi on January 22, 2021, 10:19:57 amAm 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. Yes, you're the only one. egsuh stated that they don't like to use code-tags, but it's policy on this forum to use them, so if they like it or not doesn't matter, if they don't use the tags they'll be called out for it just like any user who doesn't use them (especially as egsuh has more than 500 posts thus should know better, for posters with less posts it would be done more polite of course). ---------------------------------------------------------------------- MarkMLl · 2021-01-22 09:47 Quote from: PascalDragon on January 22, 2021, 10:31:54 amQuote from: mischi on January 22, 2021, 10:19:57 amAm 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. Yes, you're the only one. egsuh stated that they don't like to use code-tags, but it's policy on this forum to use them, so if they like it or not doesn't matter, if they don't use the tags they'll be called out for it just like any user who doesn't use them (especially as egsuh has more than 500 posts thus should know better, for posters with less posts it would be done more polite of course). Since I know that at least part of that criticism is directed at me, can I point out please that in at least one thread yesterday I was doing my best to rein in other people's criticism of an inexperienced user's code, and to keep discussion on topic and focussed on the OP's question. Speaking as a member of the community, it's generally appreciated if less-experienced users "stay told" when advised of policy by a moderator, or by somebody whose identity is specifically annotated (immediately below their posts count) as having a role as a core developer. That's my final comment in this thread, since I think OP's happy for the moment and I believe the formatting issue has been resolved. MarkMLl ---------------------------------------------------------------------- PG_97 · 2021-01-25 09:51 I was also very surprised why people were arguing here about how to write their code. It doesn't matter at all. The important thing is that it has helped the person. ---------------------------------------------------------------------- Thaddy · 2021-01-25 11:37 I did not see this yet. It is concise and modern:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var    arr: array of array of integer = ((1,2,6,7,8,9),(3,4,5));    i:array of integer;    j:integer; begin   for i in arr do             for j in i do       writeln(j);       end. [edit] Just realized ASerge gave pretty much the same answer. Anyway... ---------------------------------------------------------------------- PascalDragon · 2021-01-25 12:29 Quote from: PG_97 on January 25, 2021, 10:51:51 amI was also very surprised why people were arguing here about how to write their code. It doesn't matter at all. It's not about the code itself, it's that they don't use the tags the forum software provides to display the code to avoid it mismangling it. Just yesterday there was a post of someone who did not use code tags where [ i ] inside the was replaced by italic text. There is a reason why we want users to use the code tags! ---------------------------------------------------------------------- speter · 2021-01-25 22:51 Quote from: Thaddy on January 25, 2021, 12:37:07 pmI did not see this yet. It is concise and modern:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var    arr: array of array of integer = ((1,2,6,7,8,9),(3,4,5));    i:array of integer;    j:integer; begin   for i in arr do             for j in i do       writeln(j);       end.Thaddy, when I tried your code I got a syntax error: "NIL" expeected but "(" found (pointing to the first open bracket, line 2). I am using Laz 2.0.8 / FPC 3.0.4; do I need Laz 2.0.10 / FPC 3.2.0? cheers S. ---------------------------------------------------------------------- PascalDragon · 2021-01-26 08:13 Quote from: speter on January 25, 2021, 11:51:03 pmI am using Laz 2.0.8 / FPC 3.0.4; do I need Laz 2.0.10 / FPC 3.2.0? Yes, dynamic array constants require FPC 3.2.0 or newer. ---------------------------------------------------------------------- speter · 2021-01-26 08:43 Quote from: PascalDragon on January 26, 2021, 09:13:57 amQuote from: speter on January 25, 2021, 11:51:03 pmI am using Laz 2.0.8 / FPC 3.0.4; do I need Laz 2.0.10 / FPC 3.2.0? Yes, dynamic array constants require FPC 3.2.0 or newer. Thanks.