When there is a count in the main loop, you need to search for 3 arrays, which are announced earlier. If the element was found already in the first nested loop, then the search for the next two still happens. How to prevent this and move to the next element of the outer loop?
For example:

for i := 0 to length(ar_mas) do begin for j := 0 to length(k_mas) do begin <дСйствиС> break; end; for j := 0 to length(raz_mas) do begin <дСйствиС> break; end; for j := 0 to length(id_mas) do begin <дСйствиС> break; end; end; 

In <action>, nothing substantial happens, except for writing to a stringGrid and searching in arrays

    2 answers 2

    The simplest option is to start a flag (a boolean variable), and set it, if an element is found, at the beginning of each iteration of the outer loop, reset:

     for i := 0 to length(ar_mas) do begin flag := False; for j := 0 to length(k_mas) do begin if %условиС% then begin <дСйствиС> flag = True; break; end; end; if not flag then begin for j := 0 to length(raz_mas) do begin if %условиС% then begin <дСйствиС> flag = True; break; end; end; end; if not flag then begin for j := 0 to length(id_mas) do begin if %условиС% then begin <дСйствиС> flag = True; break; end; end; end; end; 

    You can also use goto :

     var ... label L; .... for i := 0 to length(ar_mas) do begin for j := 0 to length(k_mas) do begin if %условиС% then begin <дСйствиС> goto L; // Π² Π΄Π²ΡƒΡ… ΠΎΡΡ‚Π°Π»ΡŒΠ½Ρ‹Ρ… Ρ‚ΠΎ ΠΆΠ΅ самоС end; end; ... L: // это Π² самом ΠΊΠΎΠ½Ρ†Π΅ Ρ‚Π΅Π»Π° внСшнСго Ρ†ΠΈΠΊΠ»Π° end; 
    • one
      The third way to save money (it's better than goto) - raise TMyException - kami

    First, the not quite correct loop through the array for i := 0 to length(ar_mas) do - can lead to AV, if inside there is a call to the array elements by index from the loop. It is necessary for i := 0 to length(ar_mas) - 1 do .
    In addition to the Flownee response, you can use if j = length(k_mas) - 1 then ... as the flag if j = length(k_mas) - 1 then ...

    • Check for >= more reliable. - kot-da-vinci