iterated for loop in Macaulay2

26 views
Skip to first unread message

Reginald Anderson

unread,
Mar 21, 2024, 8:55:24 PMMar 21
to Macaulay2
Hello,

I'm fairly new to Macaulay2 and am just trying to get an iterated for-loop to work. Something like 

for i from 0 to 5 do(
    for j from 0 to 2 list i+j )

seems to be giving me trouble. At best I can get the input to go in with no error message, but also no output.

Paul Zinn-Justin

unread,
Mar 21, 2024, 8:58:05 PMMar 21
to maca...@googlegroups.com
try
for i from 0 to 5 list( for j from 0 to 2 list (i+j) )

--
You received this message because you are subscribed to the Google Groups "Macaulay2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macaulay2+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/macaulay2/08e1268b-0394-48aa-8206-93ee1ae2b839n%40googlegroups.com.

Reginald Anderson

unread,
Mar 21, 2024, 9:16:38 PMMar 21
to Macaulay2
Solid! Thanks

Frank Moore

unread,
Mar 22, 2024, 3:21:39 PMMar 22
to maca...@googlegroups.com
Let's break down your code:

The first line:

for i from 0 to 5 do (

performs what is in the parenthesis over the specified range.

Then the second line

for j from 0 to 2 list i+j )

creates a list of length three with the specified entries.  However, since the outer for loop is just a "do", the results of the command inside the for loop is discarded unless it is stored in some kind of variable.  That is why nothing is returned.

It looks like you perhaps want:

for i from 0 to 5 list (

    for j from 0 to 2 list i+j )

Best,
Frank


--
You received this message because you are subscribed to the Google Groups "Macaulay2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macaulay2+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/macaulay2/08e1268b-0394-48aa-8206-93ee1ae2b839n%40googlegroups.com.


--
Dr. W. Frank Moore
Associate Professor
Department of Mathematics and Statistics
Wake Forest University

email: moo...@wfu.edu

Reginald Anderson

unread,
Mar 22, 2024, 4:15:17 PMMar 22
to Macaulay2
Hi Frank,

Excellent. I see that for

for i from 0 to 5 do( J := for j from 0 to 2 list i+j ; print J )
I receive



Thank you.

Reply all
Reply to author
Forward
0 new messages