Jump to content

Can "for" loops have a stored value inside the range?

Recommended Posts

Im trying to put a stored value inside the range of a "for" loop, and I don't know if that's permitted, an example would be:

M = np.array([[8,8,8,8],

for j in range (4):
    for i in range(4):
        for k in range(2,M[i,j]):
            if M[i,j] % k == 0:



Link to post
Share on other sites

I don't use Python much, but it looks like it should work just fine. The variable M is available and can be passed into the range() function, so there should be no problem.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...