GDL
About building parametric objects with GDL.

Loop Parameter Reset

Lingwisyer
Guru
Hi all,

If I have a loop of 1 to N utilising the parameter X=A, where A is some previously defined value, is it possible to pick out when i=G then X=B without needing to save A to a new parameter so that for other steps the original value is still utilised?

Simplified example:

!======THESE TWO LINES CANNOT BE INCLUDED IN THE LOOP======
x = 1
n = 5
!===========================================================

FOR i = 1 to n step 1

	If i = 3 then x = 5
	text2	y,	0,	x

next i
Returns:	1	1	5	5	5
Desired:	1	1	5	1	1



Ling.

EDIT: Clarified that X is outside of the loop.
EDIT 2: Wow... I am really good at manually writing out the correct return figures...

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
15 REPLIES 15
Barry Kelly
Moderator
Just put an IF statement in your loop?
Unless I am not understanding what you need.
for i = 1 to n
X=A
if i = G then
X=B
endif
next i

Barry.
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Lingwisyer
Guru
Doesn't that change the value of X for all proceeding steps? Or has my understanding of inline definitions been flawed this whole time... I am not up to needing this yet except for when i = N where N is the final use of that value, so a none issue, but the situation popped up into my head and made a few knots...



Ling.

EDIT : Modified original post to clarify details

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Barry Kelly
Moderator
Lingwisyer wrote:
Doesn't that change the value of X for all proceeding steps?

X can only ever equal one value.
I thought you just wanted to trap a certain count or point in the loop.

You can reset the value of X as you go through the script.
It shouldn't affect where it has been used already but will all future uses.
This is assuming you are not resetting the actual parameter value.

Whenever I change a value I always store an original version of it.
X=10
X_orig = X
X=20
Then if ever I need to go back to the original value...
X= X_orig 


Maybe I don't understand exactly what you want after all.

Barry.
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Nader Belal
Mentor
Your error was in the conditional statement location


x = 1
n = 5

FOR i = 1 to n step 1
	If i = 3 then
		x = 5
	endif

	text2	y,	0,	x
next i

A good friend of mine have once told me that I´m so brute that I´m capable of creating a GDL script capable of creating GDLs.
Lingwisyer
Guru
Moonlight wrote:
Your error was in the conditional statement location


x = 1
n = 5

FOR i = 1 to n step 1
	If i = 3 then
		x = 5
	endif

	text2	y,	0,	x
next i


That just shifts the number change. Does not isolate it. I will probably just end up making a new set a parameters to temporarily store the relevant values.



Ling.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
Barry Kelly
Moderator
This works if it is what you are after.
n = 5

FOR i = 1 to n step 1
	x = 1
	If i = 3 then
		x = 5
	endif

	text2	i,	0,	x
next i

Barry.
One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Lingwisyer
Guru
X is some previously defined value, external to the loop, it cannot be statically defined here.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win11 | i9 10850K | 64GB | RX6600 Win10 | R5 2600 | 16GB | GTX1660
a few minor things:
1. you can do the if statement in one line without the "endif". looks better and fewer lines of code.
2. don't need the "step 1" as that is assumed unless otherwise defined

so it should read:

n = 5
for i = 1 to n
	x = 1
	If i = 3 then x = 5
	text2	i,	0,	x
next i
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists
looking back at your original post, it is as Barry said, just move the "x = 1" into the loop before the "if... x = 5".
that way its reinstating the x = 1 for each value, and it only get overwritten when the if statement is true.
Creator of Cadswift's parametric GDL libraries
Creator of Infinite Openings and Component Catalogues
Push the envelope & watch it bend
website: https://cadswift.com.au/
YouTube: https://www.youtube.com/user/CADSwift/playlists