How to prevent a for loop from stopping?How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?Accessing the index in 'for' loops?How do I loop through or enumerate a JavaScript object?JavaScript closure inside loops – simple practical exampleHow do I break out of nested loops in Java?Loop through an array in JavaScriptHow do I list all files of a directory?Iterating over dictionaries using 'for' loops

How to win an all out war against ants

How to design an effective polearm-bow hybrid?

Speaker impedance: rewiring four 8 Ω speakers for use with 8 Ω amp output

What is a summary of basic Jewish metaphysics or theology?

Generate random number in Unity without class ambiguity

Astable 555 circuit not oscillating

Does a bard know when a character uses their Bardic Inspiration?

Skipping same old introductions

How does shared_ptr<void> know which destructor to use?

Reasons for using monsters as bioweapons

How to enable/disable Adobe host port in terminal?

Have you been refused entry into the Federal Republic of Germany?

How to call made-up data?

Is it moral to remove/hide certain parts of a photo, as a photographer?

Confused over role of 「自分が」in this particular passage

A wiild aanimal, a cardinal direction, or a place by the water

Difference between "jail" and "prison" in German

What is the most 'environmentally friendly' way to learn to fly?

How were x-ray diffraction patterns deciphered before computers?

How can I perform a deterministic physics simulation?

Why adjustbox needs a tweak of raise=-0.3ex with enumitem?

Being told my "network" isn't PCI compliant. I don't even have a server! Do I have to comply?

Why have both: BJT and FET transistors on IC output?

Partial Fractions: Why does this shortcut method work?



How to prevent a for loop from stopping?


How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?Accessing the index in 'for' loops?How do I loop through or enumerate a JavaScript object?JavaScript closure inside loops – simple practical exampleHow do I break out of nested loops in Java?Loop through an array in JavaScriptHow do I list all files of a directory?Iterating over dictionaries using 'for' loops






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.



If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.



I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?



buy = 0
sell = 0
def checking(x,y):
for i in range (17):
if x[i]>x[i-1]:
if y[i] >y[i-1]:
global buy, sell
buy += y[i]
try:
sell +=y[i+1]
except:
sell +=y[i]

continue
return sell-buy

gains = checking(volume,close)

gains


I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.










share|improve this question
































    1















    In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.



    If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.



    I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?



    buy = 0
    sell = 0
    def checking(x,y):
    for i in range (17):
    if x[i]>x[i-1]:
    if y[i] >y[i-1]:
    global buy, sell
    buy += y[i]
    try:
    sell +=y[i+1]
    except:
    sell +=y[i]

    continue
    return sell-buy

    gains = checking(volume,close)

    gains


    I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.










    share|improve this question




























      1












      1








      1








      In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.



      If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.



      I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?



      buy = 0
      sell = 0
      def checking(x,y):
      for i in range (17):
      if x[i]>x[i-1]:
      if y[i] >y[i-1]:
      global buy, sell
      buy += y[i]
      try:
      sell +=y[i+1]
      except:
      sell +=y[i]

      continue
      return sell-buy

      gains = checking(volume,close)

      gains


      I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.










      share|improve this question
















      In my for loop, when the if statements are both true, it does what it is supposed to and then it just ends and doesn't continue through the whole loop. I tried using a continue statement after the counters buy and sell. It worked when storing the sums of the variables, but then I got an error on the return variable that says NoneType object of builtins module.



      If I leave out the continue statement, it just stores the first price it matches the if statement, but it breaks and stop summing up the other prices that match those statements.



      I know the issue is that it breaks from the for loop after the addition of the counters, maybe is the return badly indented?



      buy = 0
      sell = 0
      def checking(x,y):
      for i in range (17):
      if x[i]>x[i-1]:
      if y[i] >y[i-1]:
      global buy, sell
      buy += y[i]
      try:
      sell +=y[i+1]
      except:
      sell +=y[i]

      continue
      return sell-buy

      gains = checking(volume,close)

      gains


      I need to make a function that reads 2 dataframes, one is the volume of a stock and the other one is the close price. I want the function to check if the volume from today is greater than the one from yesterday, and if that's true then it enters another if statement, asking if the close price of today is greater than the one from yesterday. If this one is also true then it store and sums the prices of those days in the "buy" variable and store and sums the prices of the day after [i+1] in the "sell" variable. At the end it returns the difference between this two.







      python pandas loops for-loop






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 2:58









      Pikachu the Parenthesis Wizard

      2,1668 gold badges17 silver badges29 bronze badges




      2,1668 gold badges17 silver badges29 bronze badges










      asked Mar 27 at 1:32









      Guillermo CampolloGuillermo Campollo

      82 bronze badges




      82 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          0














          You're right, the indentation of the return statement was incorrect. Here's the fixed code:



          buy = 0
          sell = 0
          def checking(x,y):
          for i in range (17):
          if x[i]>x[i-1]:
          if y[i] >y[i-1]:
          global buy, sell
          buy += y[i]
          try:
          sell +=y[i+1]
          except:
          sell +=y[i]

          return sell-buy

          gains = checking(volume,close)





          share|improve this answer

























          • @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

            – Artemis Fowl
            Mar 27 at 2:36











          • Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

            – Guillermo Campollo
            Mar 28 at 14:24











          • @GuillermoCampollo See What is reputation? and Upvote privilege.

            – Artemis Fowl
            Mar 28 at 15:24


















          0














          buy = 0
          sell = 0
          def checking(x,y):
          for i in range (17):
          if x[i]>x[i-1]:
          if y[i] >y[i-1]:
          global buy, sell
          buy += y[i]
          try:
          sell +=y[i+1]
          except:
          sell +=y[i]


          return sell-buy

          gains = checking(volume,close)





          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368508%2fhow-to-prevent-a-for-loop-from-stopping%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You're right, the indentation of the return statement was incorrect. Here's the fixed code:



            buy = 0
            sell = 0
            def checking(x,y):
            for i in range (17):
            if x[i]>x[i-1]:
            if y[i] >y[i-1]:
            global buy, sell
            buy += y[i]
            try:
            sell +=y[i+1]
            except:
            sell +=y[i]

            return sell-buy

            gains = checking(volume,close)





            share|improve this answer

























            • @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

              – Artemis Fowl
              Mar 27 at 2:36











            • Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

              – Guillermo Campollo
              Mar 28 at 14:24











            • @GuillermoCampollo See What is reputation? and Upvote privilege.

              – Artemis Fowl
              Mar 28 at 15:24















            0














            You're right, the indentation of the return statement was incorrect. Here's the fixed code:



            buy = 0
            sell = 0
            def checking(x,y):
            for i in range (17):
            if x[i]>x[i-1]:
            if y[i] >y[i-1]:
            global buy, sell
            buy += y[i]
            try:
            sell +=y[i+1]
            except:
            sell +=y[i]

            return sell-buy

            gains = checking(volume,close)





            share|improve this answer

























            • @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

              – Artemis Fowl
              Mar 27 at 2:36











            • Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

              – Guillermo Campollo
              Mar 28 at 14:24











            • @GuillermoCampollo See What is reputation? and Upvote privilege.

              – Artemis Fowl
              Mar 28 at 15:24













            0












            0








            0







            You're right, the indentation of the return statement was incorrect. Here's the fixed code:



            buy = 0
            sell = 0
            def checking(x,y):
            for i in range (17):
            if x[i]>x[i-1]:
            if y[i] >y[i-1]:
            global buy, sell
            buy += y[i]
            try:
            sell +=y[i+1]
            except:
            sell +=y[i]

            return sell-buy

            gains = checking(volume,close)





            share|improve this answer













            You're right, the indentation of the return statement was incorrect. Here's the fixed code:



            buy = 0
            sell = 0
            def checking(x,y):
            for i in range (17):
            if x[i]>x[i-1]:
            if y[i] >y[i-1]:
            global buy, sell
            buy += y[i]
            try:
            sell +=y[i+1]
            except:
            sell +=y[i]

            return sell-buy

            gains = checking(volume,close)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 27 at 1:43









            Artemis FowlArtemis Fowl

            1,6934 gold badges13 silver badges28 bronze badges




            1,6934 gold badges13 silver badges28 bronze badges















            • @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

              – Artemis Fowl
              Mar 27 at 2:36











            • Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

              – Guillermo Campollo
              Mar 28 at 14:24











            • @GuillermoCampollo See What is reputation? and Upvote privilege.

              – Artemis Fowl
              Mar 28 at 15:24

















            • @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

              – Artemis Fowl
              Mar 27 at 2:36











            • Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

              – Guillermo Campollo
              Mar 28 at 14:24











            • @GuillermoCampollo See What is reputation? and Upvote privilege.

              – Artemis Fowl
              Mar 28 at 15:24
















            @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

            – Artemis Fowl
            Mar 27 at 2:36





            @GuillermoCampollo If an answer solves your problem, you can upvote and accept it.

            – Artemis Fowl
            Mar 27 at 2:36













            Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

            – Guillermo Campollo
            Mar 28 at 14:24





            Tried to upvote it but it tells me i need 15 reputation, whatever that means. But i already accepted it, thanks again

            – Guillermo Campollo
            Mar 28 at 14:24













            @GuillermoCampollo See What is reputation? and Upvote privilege.

            – Artemis Fowl
            Mar 28 at 15:24





            @GuillermoCampollo See What is reputation? and Upvote privilege.

            – Artemis Fowl
            Mar 28 at 15:24













            0














            buy = 0
            sell = 0
            def checking(x,y):
            for i in range (17):
            if x[i]>x[i-1]:
            if y[i] >y[i-1]:
            global buy, sell
            buy += y[i]
            try:
            sell +=y[i+1]
            except:
            sell +=y[i]


            return sell-buy

            gains = checking(volume,close)





            share|improve this answer





























              0














              buy = 0
              sell = 0
              def checking(x,y):
              for i in range (17):
              if x[i]>x[i-1]:
              if y[i] >y[i-1]:
              global buy, sell
              buy += y[i]
              try:
              sell +=y[i+1]
              except:
              sell +=y[i]


              return sell-buy

              gains = checking(volume,close)





              share|improve this answer



























                0












                0








                0







                buy = 0
                sell = 0
                def checking(x,y):
                for i in range (17):
                if x[i]>x[i-1]:
                if y[i] >y[i-1]:
                global buy, sell
                buy += y[i]
                try:
                sell +=y[i+1]
                except:
                sell +=y[i]


                return sell-buy

                gains = checking(volume,close)





                share|improve this answer













                buy = 0
                sell = 0
                def checking(x,y):
                for i in range (17):
                if x[i]>x[i-1]:
                if y[i] >y[i-1]:
                global buy, sell
                buy += y[i]
                try:
                sell +=y[i+1]
                except:
                sell +=y[i]


                return sell-buy

                gains = checking(volume,close)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 1:44









                Suven PandeySuven Pandey

                6713 silver badges16 bronze badges




                6713 silver badges16 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368508%2fhow-to-prevent-a-for-loop-from-stopping%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현