I have a range of memory to parse. If I find a certain sequence of bytes before the end, I interrupt the iteration. I wonder which loop I should prefer here:
while(i < end && !sequenceFound ) {
// parse
i++;
}
Or
for( i; i < end && !sequenceFound; i++ ) {
// parse
}
This is used in a method of a class that derives from a class that implements a ring buffer. The superclass provides i
and end
. My question is, which one do you think is easier to understand (expresses the intend better) for someone unfamiliar with the code?
Edit The fact that I found the sequence is needed for the further parsing of the stream. I could use break
and set sequenceFound = true
, but that would be redundant, or am I being to strict here?