CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with cycle DO WHILE

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

problem with cycle DO WHILE
PostPosted: Thu May 21, 2009 4:21 pm     Reply with quote

Hi

In my program I have one cycle but it don't make which I think make :P Someone can see and give me some ideas?

Idea on this cycle is: it out when "run=30" or when I press switches "foot" and "sens" at same time.

But now this don't out when only "run=30" :S
Code:

do {
    if(input(ABS)==1) run++;
    foot=input(PBREAK);
    sens=input(SENSOR);
   }while(run<=30 || (foot!=1 && sens!=1));   

if ((foot==1) && (sens==1))
  {
   reset_cpu();
  }

if ((codeok!=3)) turnoff();     

If someone can help me...

Kind regards
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 21, 2009 6:37 pm     Reply with quote

In order to exit the loop when run==30, or the both input switches are pressed you have to change to:
Code:
}while(run<=30 && !(foot==1 && sens==1));
or the identical:
Code:
}while(run<=30 && (foot==0 || sens==0));
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri May 22, 2009 2:01 am     Reply with quote

ckielstra wrote:
In order to exit the loop when run==30, or the both input switches are pressed you have to change to:
Code:
}while(run<=30 && !(foot==1 && sens==1));
or the identical:
Code:
}while(run<=30 && (foot==0 || sens==0));


You also need to change
while (run <= 30 &&
to
while ((run < 30) &&
If you want it to exit when run == 30.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group