I know that the for loop needs to be in the form of for (initialization; condition; increment) In this case there is a fourth part, do you know what it does?
Asked
Active
Viewed 857 times
0
-
There are only 3 parts. There are only two `;` in your code. Maybe you mistake the comma for a semicolon. – M.M Apr 01 '16 at 03:37
-
the C comma operator *is* somewhat rarely seen. If we don't already have a suitable answer around here, it wouldn't hurt to write one :) – hobbs Apr 01 '16 at 03:39
-
I did not do any mistake. I tested the code and it works. Hence this for loop it is correct. Another for loop that is used in the code is for (int b=0; b<4; b++, freq>>=8). I am confused – Andreas Apr 01 '16 at 03:40
-
Is that even valid syntax?? "Data>>=1"? ..can't be. – GisMofx Apr 01 '16 at 03:42
-
The mistake is that you said there are 4 parts but actually there are only 3 parts. The parts are separated by the `;` symbol – M.M Apr 01 '16 at 03:42
-
@GisMofx It is valid syntax, what part of it are you not sure about – M.M Apr 01 '16 at 03:43
-
@M.M I got your point and you are right. – Andreas Apr 01 '16 at 03:45
-
@M.M I just looked it up. That bitwise assignment. Never used it before. Andreas it appears it's doing i++ and data = data >>1 on each loop iteration. – GisMofx Apr 01 '16 at 03:50
-
Also, @Andreas your answer is here: http://stackoverflow.com/questions/1232176/how-to-put-two-increment-statements-in-a-c-for-loop – GisMofx Apr 01 '16 at 03:54
-
1@GisMOfx and M.M Thank you for your help. I really appreciate it – Andreas Apr 01 '16 at 03:58
1 Answers
0
There is no fourth part. The third part contains the comma operator which simply allows you to put various statements together as if one where you can't use {}
. Pretty much the only time I've ever used them is like this (and while
) where you have a single place where you want to do more than one thing.
In this case, the last part of the loop is both incrementing i (i++
) and shifting data
right once (dividing by 2) at the end of each iteration

LoztInSpace
- 5,584
- 1
- 15
- 27