ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 13 Sep 2021 11:23:08 +0200While loopshttps://ask.sagemath.org/question/58989/while-loops/The goal to find the smallest value of a that satisfies the condition below. I realise I could use "if" instead of "while", but len(Lpathcellsdim4[s]) is big, and I want the computer to stop after it finds the first value of a satisfying the condition. I would be grateful for suggestions. Are there sage worksheets or tutorials to learn this type of thing? I have other, more complicated examples, where I want the computer to stop after it has found the first of many solutions.
The following gives an error "TypeError: argument of type 'sage.rings.integer.Integer' is not iterable"
b=0
for a in range(len(Lpathcellsdim4[s])):
while Lvectorspolyfacesdim5[Lpathcellsdim4[s][a][0]][Lpathcellsdim4[s][a][1]][Lpathcellsdim4[s][a][2]] not in Lsimppdim5[n][5][5]:
b=b+1Mon, 13 Sep 2021 10:14:57 +0200https://ask.sagemath.org/question/58989/while-loops/Comment by Ingrid for <p>The goal to find the smallest value of a that satisfies the condition below. I realise I could use "if" instead of "while", but len(Lpathcellsdim4[s]) is big, and I want the computer to stop after it finds the first value of a satisfying the condition. I would be grateful for suggestions. Are there sage worksheets or tutorials to learn this type of thing? I have other, more complicated examples, where I want the computer to stop after it has found the first of many solutions.</p>
<p>The following gives an error "TypeError: argument of type 'sage.rings.integer.Integer' is not iterable"</p>
<pre><code>b=0
for a in range(len(Lpathcellsdim4[s])):
while Lvectorspolyfacesdim5[Lpathcellsdim4[s][a][0]][Lpathcellsdim4[s][a][1]][Lpathcellsdim4[s][a][2]] not in Lsimppdim5[n][5][5]:
b=b+1
</code></pre>
https://ask.sagemath.org/question/58989/while-loops/?comment=58992#post-id-58992Thanks Emmanuel, there are some helpful examples there.Mon, 13 Sep 2021 11:23:08 +0200https://ask.sagemath.org/question/58989/while-loops/?comment=58992#post-id-58992Comment by Emmanuel Charpentier for <p>The goal to find the smallest value of a that satisfies the condition below. I realise I could use "if" instead of "while", but len(Lpathcellsdim4[s]) is big, and I want the computer to stop after it finds the first value of a satisfying the condition. I would be grateful for suggestions. Are there sage worksheets or tutorials to learn this type of thing? I have other, more complicated examples, where I want the computer to stop after it has found the first of many solutions.</p>
<p>The following gives an error "TypeError: argument of type 'sage.rings.integer.Integer' is not iterable"</p>
<pre><code>b=0
for a in range(len(Lpathcellsdim4[s])):
while Lvectorspolyfacesdim5[Lpathcellsdim4[s][a][0]][Lpathcellsdim4[s][a][1]][Lpathcellsdim4[s][a][2]] not in Lsimppdim5[n][5][5]:
b=b+1
</code></pre>
https://ask.sagemath.org/question/58989/while-loops/?comment=58991#post-id-58991- Your example is unreadable, even
after reformatting. Could you give us
a smaller example ?
- The error messages says that you are
trying to index something that is an
integer ; this is probably related to
the nature of the objects you are
using and unrelated to your `while`
loop.
- Nothing in the `while` condition
depends on `b` : this loop is
effectively infinite.
- [This](https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming)
and
[this](https://docs.python.org/3/tutorial/controlflow.html)
might be of some interest...Mon, 13 Sep 2021 11:04:56 +0200https://ask.sagemath.org/question/58989/while-loops/?comment=58991#post-id-58991Comment by FrédéricC for <p>The goal to find the smallest value of a that satisfies the condition below. I realise I could use "if" instead of "while", but len(Lpathcellsdim4[s]) is big, and I want the computer to stop after it finds the first value of a satisfying the condition. I would be grateful for suggestions. Are there sage worksheets or tutorials to learn this type of thing? I have other, more complicated examples, where I want the computer to stop after it has found the first of many solutions.</p>
<p>The following gives an error "TypeError: argument of type 'sage.rings.integer.Integer' is not iterable"</p>
<pre><code>b=0
for a in range(len(Lpathcellsdim4[s])):
while Lvectorspolyfacesdim5[Lpathcellsdim4[s][a][0]][Lpathcellsdim4[s][a][1]][Lpathcellsdim4[s][a][2]] not in Lsimppdim5[n][5][5]:
b=b+1
</code></pre>
https://ask.sagemath.org/question/58989/while-loops/?comment=58990#post-id-58990use next and iter. See any python manual.Mon, 13 Sep 2021 10:38:46 +0200https://ask.sagemath.org/question/58989/while-loops/?comment=58990#post-id-58990