So I need to make it start from 1 and go up by odds so like 1 3 5 7
and I need to make it stop before it reaches the integer value
cout << "Loop 3: ";
for(i=1; i>=integer; i+= 2)
{
cout << i << " ";
}
it works but doesnt stop
Printable View
So I need to make it start from 1 and go up by odds so like 1 3 5 7
and I need to make it stop before it reaches the integer value
cout << "Loop 3: ";
for(i=1; i>=integer; i+= 2)
{
cout << i << " ";
}
it works but doesnt stop
Well, if you know the "the integer value" to stop if it has reached then what is the problem to check your i variable? :confused:
Then why you are using i>=integer condition to end the for loop instead of using i < integer (or i <= integer)?Quote:
...I need to make it stop before it reaches the integer value
Until you understand how a for-loop works I suggest you use a while-loop instead. This is equivalent to the for-loop above.
As you can see you're looping WHILE i>=integer. Is that what you want?Code:i=1; // first parameter of for-loop
while (i>=integer) // second parameter
{
cout << i << " ";
i+= 2; // third parameter
}