First of all, in the condition for that while-loop, you're using the comma wrong:
The C++ Specification section 5.18, page 92
A pair of expressions separated by a comma is evaluated left-to-right and the value of the left expression is
discarded. The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions
are not applied to the left expression. All side effects (1.9) of the left expression, except for the
destruction of temporaries (12.2), are performed before the evaluation of the right expression. The type and
value of the result are the type and value of the right operand; the result is an lvalue if its right operand is.
In contexts where comma is given a special meaning, [Example: in lists of arguments to functions (5.2.2)
and lists of initializers (8.5) ] the comma operator as described in clause 5 can appear only in parentheses.
[Example:
f(a, (t=3, t+2), c);
has three arguments, the second of which has the value 5. ]
So for your while-loop, only
count != numberOfItems is used. You should use the logical and-operator (
&&) instead of the comma-operator.
As for the for-loop, it's also a bit different from what you have. The structure for a for-loop is (also in the C++ Specification; section 6.5.3, page 99):
for(initialisation;condition;expression)
Where
initialisation is executed before the loop starts, and
expression is executed after each iteration (which makes it a good place to increment your counter). The loop stops when
condition is false at the start of an iteration (just like a while loop).