what the hell!!!

I put in my code and the compiler keeps saying
'<' : operator has no effect; expected operator with side-effect

heres the code
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main ()
{
int K= 1;
for (K<4;K<=8;K +=1) 
{
	cout<<K<<", ";
return 0;
}


I dont see anything wrong with this
what am I doing wrong???
K=4
for works like so:

 
for( initialization; condition; iteration )


"initialization" is done once when the loop starts. This is typically to set your counter value to 0 or whatever starting point you want to count from.

"condition" is checked every time the loop is about to repeat. If the condition evaluates to true, the loop repeats. If it evaluates to false, the loop stops.

"iteration" is performed every time the loop completes. Typically it is used to increment your counter.


Now --- you're putting < (a conditional operator -- you're checking to see if K is less than 4) in your initialization. As the error suggests, that has no effect. What exactly are you trying to accomplish there?

EDIT: or yeah, what blackcoder said... although I wasn't sure that's what you meant because you set K to 1 just above the loop.

Also, your topic sucks. Topics are for briefly describing the problem. Try to do that in the future.
Last edited on
blackcoder41
so your saying what ever k starts off with in the for loop thats what it should be initialized too???
thanks fellas I understand now
deeply apreciated!!!
Topic archived. No new replies allowed.