How to programmatically specify multiple iterators?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












How to use Row[Table[B[i],0,i,i,0,2],","] directly in Do command? I mean that the following command



Row[Table[B[i],0,i,i,0,2],","]


gives



B[0], 0, 0,B[1], 0, 1,B[2],0,2


But, the following command returns the error




"Do::nliter: Non-list iterator Row[Table[B[i], 0, i, i, 0, 2], ,] at position 2 does not evaluate to a real numeric value."




Do[Print[B[0]+B[1]+B[2]],Row[Table[B[i],0,i,i,0,2],","]]


Of course, one can type instead by hand the following:



Do[Print[B[0]+B[1]+B[2]],B[0],0,0,B[1],0,1,B[2],0,2] 


But, I feel that typing an output by hand again is not really an optimal method.










share|improve this question









New contributor




veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    3
    down vote

    favorite












    How to use Row[Table[B[i],0,i,i,0,2],","] directly in Do command? I mean that the following command



    Row[Table[B[i],0,i,i,0,2],","]


    gives



    B[0], 0, 0,B[1], 0, 1,B[2],0,2


    But, the following command returns the error




    "Do::nliter: Non-list iterator Row[Table[B[i], 0, i, i, 0, 2], ,] at position 2 does not evaluate to a real numeric value."




    Do[Print[B[0]+B[1]+B[2]],Row[Table[B[i],0,i,i,0,2],","]]


    Of course, one can type instead by hand the following:



    Do[Print[B[0]+B[1]+B[2]],B[0],0,0,B[1],0,1,B[2],0,2] 


    But, I feel that typing an output by hand again is not really an optimal method.










    share|improve this question









    New contributor




    veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      How to use Row[Table[B[i],0,i,i,0,2],","] directly in Do command? I mean that the following command



      Row[Table[B[i],0,i,i,0,2],","]


      gives



      B[0], 0, 0,B[1], 0, 1,B[2],0,2


      But, the following command returns the error




      "Do::nliter: Non-list iterator Row[Table[B[i], 0, i, i, 0, 2], ,] at position 2 does not evaluate to a real numeric value."




      Do[Print[B[0]+B[1]+B[2]],Row[Table[B[i],0,i,i,0,2],","]]


      Of course, one can type instead by hand the following:



      Do[Print[B[0]+B[1]+B[2]],B[0],0,0,B[1],0,1,B[2],0,2] 


      But, I feel that typing an output by hand again is not really an optimal method.










      share|improve this question









      New contributor




      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      How to use Row[Table[B[i],0,i,i,0,2],","] directly in Do command? I mean that the following command



      Row[Table[B[i],0,i,i,0,2],","]


      gives



      B[0], 0, 0,B[1], 0, 1,B[2],0,2


      But, the following command returns the error




      "Do::nliter: Non-list iterator Row[Table[B[i], 0, i, i, 0, 2], ,] at position 2 does not evaluate to a real numeric value."




      Do[Print[B[0]+B[1]+B[2]],Row[Table[B[i],0,i,i,0,2],","]]


      Of course, one can type instead by hand the following:



      Do[Print[B[0]+B[1]+B[2]],B[0],0,0,B[1],0,1,B[2],0,2] 


      But, I feel that typing an output by hand again is not really an optimal method.







      list-manipulation row do






      share|improve this question









      New contributor




      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 15 mins ago









      Carl Woll

      56.7k272147




      56.7k272147






      New contributor




      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 51 mins ago









      veo

      1254




      1254




      New contributor




      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      veo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          What you actually want is to create a Sequence from the Table to be used as your iterators.



          You can do this with



          Do[Print[B[0] + B[1] + B[2]], Sequence @@ Table[B[i], 0, i, i, 0, 2] // 
          Evaluate]

          (*0
          1
          2
          1
          2
          3*)


          Or, so you don't have to force evaluation,



          Do[Print[B[0] + B[1] + B[2]], ##] & @@ Table[B[i], 0, i, i, 0, 2]





          share|improve this answer





























            up vote
            2
            down vote













            Do[Print[B[0] + B[1] + B[2]], 
            Evaluate[Sequence @@ First@ Row[Table[B[i], 0, i, i, 0, 2], ","]]]


            or



            row = Row[Table[B[i], 0, i, i, 0, 2], ","];
            Do[Print[B[0] + B[1] + B[2]], Evaluate[Sequence @@ row[[1]]]]





            share|improve this answer





























              up vote
              1
              down vote













              Perhaps you can avoid Do and instead use Tuples:



              Tuples @ Range[0, 0, 1, 2]



              0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 1, 2




              You can then use Total to sum each tuple:



              Total[
              Tuples @ Range[0, 0, 1, 2],
              2
              ]



              0, 1, 2, 1, 2, 3







              share|improve this answer




















                Your Answer




                StackExchange.ifUsing("editor", function ()
                return StackExchange.using("mathjaxEditing", function ()
                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
                );
                );
                , "mathjax-editing");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "387"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );






                veo is a new contributor. Be nice, and check out our Code of Conduct.









                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181912%2fhow-to-programmatically-specify-multiple-iterators%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                4
                down vote



                accepted










                What you actually want is to create a Sequence from the Table to be used as your iterators.



                You can do this with



                Do[Print[B[0] + B[1] + B[2]], Sequence @@ Table[B[i], 0, i, i, 0, 2] // 
                Evaluate]

                (*0
                1
                2
                1
                2
                3*)


                Or, so you don't have to force evaluation,



                Do[Print[B[0] + B[1] + B[2]], ##] & @@ Table[B[i], 0, i, i, 0, 2]





                share|improve this answer


























                  up vote
                  4
                  down vote



                  accepted










                  What you actually want is to create a Sequence from the Table to be used as your iterators.



                  You can do this with



                  Do[Print[B[0] + B[1] + B[2]], Sequence @@ Table[B[i], 0, i, i, 0, 2] // 
                  Evaluate]

                  (*0
                  1
                  2
                  1
                  2
                  3*)


                  Or, so you don't have to force evaluation,



                  Do[Print[B[0] + B[1] + B[2]], ##] & @@ Table[B[i], 0, i, i, 0, 2]





                  share|improve this answer
























                    up vote
                    4
                    down vote



                    accepted







                    up vote
                    4
                    down vote



                    accepted






                    What you actually want is to create a Sequence from the Table to be used as your iterators.



                    You can do this with



                    Do[Print[B[0] + B[1] + B[2]], Sequence @@ Table[B[i], 0, i, i, 0, 2] // 
                    Evaluate]

                    (*0
                    1
                    2
                    1
                    2
                    3*)


                    Or, so you don't have to force evaluation,



                    Do[Print[B[0] + B[1] + B[2]], ##] & @@ Table[B[i], 0, i, i, 0, 2]





                    share|improve this answer














                    What you actually want is to create a Sequence from the Table to be used as your iterators.



                    You can do this with



                    Do[Print[B[0] + B[1] + B[2]], Sequence @@ Table[B[i], 0, i, i, 0, 2] // 
                    Evaluate]

                    (*0
                    1
                    2
                    1
                    2
                    3*)


                    Or, so you don't have to force evaluation,



                    Do[Print[B[0] + B[1] + B[2]], ##] & @@ Table[B[i], 0, i, i, 0, 2]






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 37 mins ago

























                    answered 42 mins ago









                    That Gravity Guy

                    42625




                    42625




















                        up vote
                        2
                        down vote













                        Do[Print[B[0] + B[1] + B[2]], 
                        Evaluate[Sequence @@ First@ Row[Table[B[i], 0, i, i, 0, 2], ","]]]


                        or



                        row = Row[Table[B[i], 0, i, i, 0, 2], ","];
                        Do[Print[B[0] + B[1] + B[2]], Evaluate[Sequence @@ row[[1]]]]





                        share|improve this answer


























                          up vote
                          2
                          down vote













                          Do[Print[B[0] + B[1] + B[2]], 
                          Evaluate[Sequence @@ First@ Row[Table[B[i], 0, i, i, 0, 2], ","]]]


                          or



                          row = Row[Table[B[i], 0, i, i, 0, 2], ","];
                          Do[Print[B[0] + B[1] + B[2]], Evaluate[Sequence @@ row[[1]]]]





                          share|improve this answer
























                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            Do[Print[B[0] + B[1] + B[2]], 
                            Evaluate[Sequence @@ First@ Row[Table[B[i], 0, i, i, 0, 2], ","]]]


                            or



                            row = Row[Table[B[i], 0, i, i, 0, 2], ","];
                            Do[Print[B[0] + B[1] + B[2]], Evaluate[Sequence @@ row[[1]]]]





                            share|improve this answer














                            Do[Print[B[0] + B[1] + B[2]], 
                            Evaluate[Sequence @@ First@ Row[Table[B[i], 0, i, i, 0, 2], ","]]]


                            or



                            row = Row[Table[B[i], 0, i, i, 0, 2], ","];
                            Do[Print[B[0] + B[1] + B[2]], Evaluate[Sequence @@ row[[1]]]]






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 36 mins ago

























                            answered 42 mins ago









                            kglr

                            160k8184384




                            160k8184384




















                                up vote
                                1
                                down vote













                                Perhaps you can avoid Do and instead use Tuples:



                                Tuples @ Range[0, 0, 1, 2]



                                0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 1, 2




                                You can then use Total to sum each tuple:



                                Total[
                                Tuples @ Range[0, 0, 1, 2],
                                2
                                ]



                                0, 1, 2, 1, 2, 3







                                share|improve this answer
























                                  up vote
                                  1
                                  down vote













                                  Perhaps you can avoid Do and instead use Tuples:



                                  Tuples @ Range[0, 0, 1, 2]



                                  0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 1, 2




                                  You can then use Total to sum each tuple:



                                  Total[
                                  Tuples @ Range[0, 0, 1, 2],
                                  2
                                  ]



                                  0, 1, 2, 1, 2, 3







                                  share|improve this answer






















                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    Perhaps you can avoid Do and instead use Tuples:



                                    Tuples @ Range[0, 0, 1, 2]



                                    0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 1, 2




                                    You can then use Total to sum each tuple:



                                    Total[
                                    Tuples @ Range[0, 0, 1, 2],
                                    2
                                    ]



                                    0, 1, 2, 1, 2, 3







                                    share|improve this answer












                                    Perhaps you can avoid Do and instead use Tuples:



                                    Tuples @ Range[0, 0, 1, 2]



                                    0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 1, 2




                                    You can then use Total to sum each tuple:



                                    Total[
                                    Tuples @ Range[0, 0, 1, 2],
                                    2
                                    ]



                                    0, 1, 2, 1, 2, 3








                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 16 mins ago









                                    Carl Woll

                                    56.7k272147




                                    56.7k272147




















                                        veo is a new contributor. Be nice, and check out our Code of Conduct.









                                         

                                        draft saved


                                        draft discarded


















                                        veo is a new contributor. Be nice, and check out our Code of Conduct.












                                        veo is a new contributor. Be nice, and check out our Code of Conduct.











                                        veo is a new contributor. Be nice, and check out our Code of Conduct.













                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181912%2fhow-to-programmatically-specify-multiple-iterators%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Comments

                                        Popular posts from this blog

                                        What does second last employer means? [closed]

                                        Installing NextGIS Connect into QGIS 3?

                                        One-line joke