<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Generating a square with rotating FOR-NEXT loop - why isn't it working? in GDL</title>
    <link>https://community.graphisoft.com/t5/GDL/Generating-a-square-with-rotating-FOR-NEXT-loop-why-isn-t-it/m-p/684367#M8118</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm making a 2D script where I define the side of a square, and then I want to use a FOR-NEXT loop to generate the rest of the square.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've made two scripts that I think should work exactly the same, but they don't - can anytone illuminate me as to why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First I made a manual script. This generates a perfect square as intended:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;side = 1

LINE2 0, 0, side, 0 ! bottom edge

ADD2 side, 0
ROT2 90

LINE2 0, 0, side, 0 ! right edge

ADD2 side, 0
ROT2 90

LINE2 0, 0, side, 0 ! top edge

ADD2 side, 0
ROT2 90

LINE2 0, 0, side, 0 ! left edge

END&lt;/LI-CODE&gt;
&lt;P&gt;Then I try to make the same script as a FOR-NEXT loop:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;side = 1

FOR i = 1 TO 4
    ROT2 90*(i-1)
    LINE2 0, 0, side, 0
    ADD2 side, 0     ! move to the endpoint for the next edge
NEXT i

END&lt;/LI-CODE&gt;
&lt;P&gt;This script only generates the bottom and right edge - why?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would imagine that increasing i&amp;gt;4 would generate an overlapping loop, but the geometry just keeps getting more and more wonky - what is the logic I'm not getting?&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;: 20 seconds after posting I realised I just needed to change the rotation to a simple 90 degrees turn at the bottom of the transformation stack instead of a "fancy" 90*(i-1) at the start.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;I don't see a button to delete this post, so I'm leaving it up to be shamed.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;FOR i = 1 TO 4
    LINE2 0, 0, side, 0
    ADD2 side, 0     ! move to the endpoint for the next edge
    ROT2 90
NEXT i&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Nov 2025 07:44:31 GMT</pubDate>
    <dc:creator>Bilkins</dc:creator>
    <dc:date>2025-11-20T07:44:31Z</dc:date>
    <item>
      <title>Generating a square with rotating FOR-NEXT loop - why isn't it working?</title>
      <link>https://community.graphisoft.com/t5/GDL/Generating-a-square-with-rotating-FOR-NEXT-loop-why-isn-t-it/m-p/684367#M8118</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm making a 2D script where I define the side of a square, and then I want to use a FOR-NEXT loop to generate the rest of the square.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've made two scripts that I think should work exactly the same, but they don't - can anytone illuminate me as to why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First I made a manual script. This generates a perfect square as intended:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;side = 1

LINE2 0, 0, side, 0 ! bottom edge

ADD2 side, 0
ROT2 90

LINE2 0, 0, side, 0 ! right edge

ADD2 side, 0
ROT2 90

LINE2 0, 0, side, 0 ! top edge

ADD2 side, 0
ROT2 90

LINE2 0, 0, side, 0 ! left edge

END&lt;/LI-CODE&gt;
&lt;P&gt;Then I try to make the same script as a FOR-NEXT loop:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;side = 1

FOR i = 1 TO 4
    ROT2 90*(i-1)
    LINE2 0, 0, side, 0
    ADD2 side, 0     ! move to the endpoint for the next edge
NEXT i

END&lt;/LI-CODE&gt;
&lt;P&gt;This script only generates the bottom and right edge - why?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would imagine that increasing i&amp;gt;4 would generate an overlapping loop, but the geometry just keeps getting more and more wonky - what is the logic I'm not getting?&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;: 20 seconds after posting I realised I just needed to change the rotation to a simple 90 degrees turn at the bottom of the transformation stack instead of a "fancy" 90*(i-1) at the start.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;I don't see a button to delete this post, so I'm leaving it up to be shamed.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;FOR i = 1 TO 4
    LINE2 0, 0, side, 0
    ADD2 side, 0     ! move to the endpoint for the next edge
    ROT2 90
NEXT i&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Nov 2025 07:44:31 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Generating-a-square-with-rotating-FOR-NEXT-loop-why-isn-t-it/m-p/684367#M8118</guid>
      <dc:creator>Bilkins</dc:creator>
      <dc:date>2025-11-20T07:44:31Z</dc:date>
    </item>
  </channel>
</rss>

