954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Condition in for Loop

Here is code which i am using Please check it first

for(x=0; x<=y; x++){
if(a=x||b=x||c=x){
printf("Value =%d",x);
}
}

In this code x is a base for the loop i want loop till y (variable). Now inside the loop i want to check a condition if x (variable) is equal to any of these Variables a,b,c then print the Value of x.
This code is not working i get Lvalue error with it.
Regards

DezineGenerator
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

The = operator is for assignment in C++. You want the == operator to compare equality:

for (x = 0; x <= y; x++)
{
    if (a == x || b == x || c == x)
    {
        printf("Value = %d", x);
    }
}
deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

Thank you.

DezineGenerator
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: