Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

Loop Parameter Reset

Lingwisyer
Virtuoso
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...
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

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 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

Lingwisyer
Virtuoso
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
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

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 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

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
Virtuoso
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.
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

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 25
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Dell Precision 3510 - i7 6820HQ @ 2.70GHz, 16GB RAM, AMD FirePro W5130M, Windows 10

Lingwisyer
Virtuoso
X is some previously defined value, external to the loop, it cannot be statically defined here.
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

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

Lingwisyer
Virtuoso
Start of the script:
d = B - gs_fw_lower - gs_fw_upper - 2 * gs_int_fw				!Louvre space
IF louvre_over <= 0 then							!If NO louvre overlap	
		n = int(d /(gs_louvre_width - louvre_over))
		dp = gs_louvre_width - louvre_over
	ELSE
		dp = gs_louvre_thk / ( cos ( atn ( ( gs_louvre_width - louvre_over) / gs_louvre_thk) ) )
		n = int(d / dp) + 1
endIF

The loop (for one set of conditionals):
FOR i=1 to n

	...

	IF Louvred_sealside = "Both" then
		IF i = 1 | i = n then
			gs_louvre_opening_angle = gs_louvre_opening_max
			gs_louvre_width = sqr((d - (dp * (n - 1) + Louvre_over))^2 - (gs_louvre_thk)^2 ) + Louvre_over
		endIF
	endIF

	...

	cprism_ louvtopmat, louvbotmat, louvsidemat,
		5, gs_louvre_thk,
		-a / 2 + gs_fw_side_right + gs_int_fw,	-(gs_louvre_width) / 2,	_status,
		-a / 2 + gs_fw_side_right + gs_int_fw,	 (gs_louvre_width) / 2,	_status,
		 a / 2 - gs_fw_side_left - gs_int_fw,	 (gs_louvre_width) / 2,	_status,
		 a / 2 - gs_fw_side_left - gs_int_fw,	-(gs_louvre_width) / 2,	_status,
		-a / 2 + gs_fw_side_right + gs_int_fw,	-(gs_louvre_width) / 2,	-1

	...

next i
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

Win10 | R5 2600 | 16GB | GTX1660

A_ Smith
Booster
if it's forbidden to repeat x=1 or use new parameter, n=5 like this:

FOR i = 1 to n step 1
	If i = 3 then x = 5 then
	text2	y,	0,	x
	x=1
	endif
	text2	y,	0,	x
next i
maybe if you know precisely when it occurs just exclude from the loop? (though it looks awful)
FOR i=1 to 2 ...
if i=3 then ...
FOR i=4 to n ...
AC 22, 24 | Win 10

Lingwisyer
Virtuoso
A. wrote:
maybe if you know precisely when it occurs just exclude from the loop? (though it looks awful)
FOR i=1 to 2 ...
if i=3 then ...
FOR i=4 to n ...

Doing so would basically double the script length... Easier to just populate a half dozen new variables to my list.
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

Win10 | R5 2600 | 16GB | GTX1660

Peter Baksa
Graphisoft
Graphisoft
Lingwisyer wrote:
...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?
You just said it:
if i = G then X = B else X = A
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

Lingwisyer
Virtuoso
Peter wrote:
Lingwisyer wrote:
...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?
You just said it:
if i = G then X = B else X = A

Was hoping there would be a way that did not involve rewriting a dozen macros to use a dependent variable rather than the independent, and by the sounds of it, there is not so I will be needing to rewrite them at some point.

C = X
A = X

...

if i = G then C = B else C = A

...

*replace X with C in all dependent macros*



Sorry for looking for a lazy way out,
Ling.
AC18-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | E5620 x 2 | 24GB | K2200

Win10 | R5 2600 | 16GB | GTX1660

Peter Baksa
Graphisoft
Graphisoft
In parameter calls you can assign variables to parameters:
call "macro" parameters A = something, ....
The subsequent calls from "macro" will use the value of something.
If you don't want to write each parameter in the call, write just the modified ones:
call "macro" parameters all, A = something
Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!