Why "for" loop expression has no effect ?

We used Keil tools to compile our embedded c++ code.

for ( i = 0, idx_reg_curr = j ;  i < 10,  idx_reg_curr < (j+10) ;   i++,  idx_reg_curr++ )

In above for loop, I get the following compile warning:

warning:   #174-D:  expression has no effect


Why doesn't this expression has effect ?
LVL 1
naseeamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

naseeamAuthor Commented:
for (short j = 0; j < 40; j+= 10)
{
   for (i = 0, idx_reg_curr = j; i < 10, idx_reg_curr < (j+10); i++, idx_reg_curr++)
   {
       SCODesc[i * 2] = (char)(responseBuffer[idx_reg_curr] & 0xFF);
       SCODesc[i * 2 + 1] = (char)(responseBuffer[idx_reg_curr] >> 8);
   }

   ParameterManager::GetParameterById((ParameterId)(Parameters::Info[idx_id++].Id))->setValue((char*)SCODesc, 20);

}

Open in new window

0
sarabandeCommented:
i < 10,  idx_reg_curr < (j+10)

exchange the expression by

 i < 10 ||  idx_reg_curr < (j+10)

Open in new window



if you want to have both counters to be below the upper boundary.

otherwise you may use logical &&.

note, the , (comma) allows to execute two statements. but putting a comma in a logical expression has no effect. the compiler only would check the first expression.

Sara
0
sarabandeCommented:
sorry, you need the && to be sure that both counters are valid.

for (i = 0, idx_reg_curr = j; i < 10 && idx_reg_curr < (j+10); i++, idx_reg_curr++)

Open in new window


Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
naseeamAuthor Commented:
Problem solved and explained very quickly.  Thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.