Hi, I'd like to have a for condition with two interrupting conditions:

for(temp=hl;temp!=NULL,bOver1==true; temp=temp->next){
	bOver=false;
	int I=0;
	while(bOver==false){
		if(cu.Chars('S')[I]>temp->custs.Chars('S')[I]){
			bOver=true;
			prev=temp;
		}else if(cu.Chars('S')[I]<temp->custs.Chars('S')[I]){
//FOUND THE ONE GREATER: PREV STAYS THE ONE BEFORE AND LOOP MUST END HERE!
			bOver=true;
			bOver1=true;
		}
		i++;
	}
}

This is a part of the code, where I try to put order in a list, simply looking for the previous one, checking the surname. As you can see I tried to put 2 conditions in the for, so that when I find the greater one, I exit the while (surname checker) and then the for (the bOver1 is a boolean flag: false = continue, true = stop).
When I launch it the for loop is simply jumped, even if the list has 3 variables and bOver1 is set to false in the declaration.
What's wrong? Is it possible to make something like I asked?
Thank you!

Recommended Answers

All 3 Replies

Try rewriting like so

for(temp=hl;(temp!=NULL) || (bOver1==true); temp=temp->next)

It goes in even if bOver1 becomes true...

Reverse thinking I wrote:

for(temp=hl;(temp!=NULL)&&(bOver1==false); temp=temp->next)

This works. Thank you for being Flash in answers anyway =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.