BBNN
BBNN

Reputation: 139

How can I resolve "Not all control paths return a value" error for integer

I have the error "Not all control paths return a value". I've seen it before and have been able to resolve it for a simple bool return value. This is a bit different and seems to be a challenge for me since it has a for-loop and at the same time returns integers. Please see my code below:

int ArrowedCandleIndex  () {

      for (int i=0; i<NumBars; i++)
      {
         double dnArrow = iCustom(Symbol(),Period(),ARROWS_SIGNAL_NAME,ARROWS_SIGNAL_BUFFER_DN,i);
         double upArrow = iCustom(Symbol(),Period(),ARROWS_SIGNAL_NAME,ARROWS_SIGNAL_BUFFER_UP,i);

         if ((dnArrow!=EMPTY_VALUE) && (DoubleToStr(dnArrow,Digits()) != "0.00000"))  {

            currentArrowedCandleIndex = NumBars;

            return currentArrowedCandleIndex;
            }
         if ((upArrow!=EMPTY_VALUE) && (DoubleToStr(upArrow,Digits()) != "0.00000"))  {
            currentArrowedCandleIndex = NumBars;

            return currentArrowedCandleIndex;
            }
      }
  }

How can I resolve this issue?

Upvotes: 0

Views: 305

Answers (1)

user3666197
user3666197

Reputation: 1

Q : "How can I resolve this ( "Not all control paths return a value" ) issue?"

int ArrowedCandleIndex  () {

      for ( int i = 0; i <  NumBars; i++ )
      {
         ...    
         if (  (  EMPTY_VALUE != dnArrow )
            && ( "0.00000"    != DoubleToStr( dnArrow, Digits() ) )
               ) {
                 ...
                 return currentArrowedCandleIndex; // ------------ JIT/RET--(a)
         }

         if (  (  EMPTY_VALUE != upArrow )
            && ( "0.00000"    != DoubleToStr( upArrow, Digits() ) )
               ) {
                 ...
                 return currentArrowedCandleIndex; // ------------ JIT/RET--(b)
            }
      }
      return EMPTY_VALUE; // ------------------------------------- JIT/RET--(c)
  }

Upvotes: 1

Related Questions