Timeline for Is there a Break[] equivalent for short-circuiting in Table?
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 19, 2017 at 19:40 | comment | added | Mr.Wizard |
@anderstood Table does not keep partial results so you would need to accumulate those manually, with e.g. Reap and Sow or a similar mechanism. See: (313) and (7566). Consider also using "block based" methods e.g. in my answer to (21584).
|
|
Dec 18, 2017 at 18:37 | comment | added | anderstood |
What if you wanted to interrupt Table , let's say at step 2 , but have it return what it would have had returned if it had stopped at 2? I mean, Table[If[i < 3, i, Return["Exit", Table]], {i, 100}] does not return the same as Table[i, {i, 2}] . What if I wanted Table[If[i<3, i, ......], {i, 100}] to return {1, 2} ?
|
|
Apr 13, 2017 at 12:55 | history | edited | CommunityBot |
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
|
|
Jan 28, 2013 at 15:43 | vote | accept | Andrew | ||
Jan 27, 2013 at 9:07 | comment | added | Leonid Shifrin | @Ajasja Very good point! I too was bitten by this several times in the past. | |
Jan 26, 2013 at 19:28 | comment | added | Jens | @Ajasja Thanks -- I've never tried it, but I believe you. It's one of those answers that are interesting but could lead newbies to commit horrible crimes... | |
Jan 26, 2013 at 19:01 | comment | added | Ajasja |
@Jens Return is very dangerous in compiled functions. If you in-line a compiled function with Return into another compiled function, the first Return will exit both. I can find an example if you like...
|
|
Jan 26, 2013 at 18:58 | comment | added | Ajasja | +1 I agree. The particular example in the question might have better solutions, but the Q&A in general is very interesting. | |
Jan 26, 2013 at 18:22 | comment | added | Mr.Wizard | @Jens Thanks. I cannot always write a-guide-to-a-better-way answers (though I try) and sometimes the direct answer is more interesting to me. | |
Jan 26, 2013 at 18:22 | comment | added | Jens |
Actually, I wouldn't use it in compiled functions either. Then For and While seems fine.
|
|
Jan 26, 2013 at 18:21 | history | edited | Mr.Wizard | CC BY-SA 3.0 |
added 295 characters in body
|
Jan 26, 2013 at 18:17 | comment | added | Jens |
+1 since it answers the question, but I wouldn't do it that way. Except maybe in compiled functions - I wonder if that second arg works with Compile ...
|
|
Jan 26, 2013 at 18:13 | history | edited | Mr.Wizard | CC BY-SA 3.0 |
added 187 characters in body
|
Jan 26, 2013 at 18:07 | history | answered | Mr.Wizard | CC BY-SA 3.0 |