Solved

A newbie question....

Posted on 2000-02-18
3
196 Views
Last Modified: 2010-04-15
I'm new to progamming in C. I've done extensive work in Perl which is pretty similar.

My problem is that I've got a loop that doesn't seem to be working right.

while (timein !=0 && timeout !=0) {
   execute code....
}

However, it seems to be quitting too early. If "timein = 0" it will stop OR if "timeout = 0" it will stop.

I need to only stop if both conditions are met. Do I have the syntax wrong?

Extra points for my stupidty :)

Thanks!
0
Comment
Question by:drummond
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:Ready4Dis
ID: 2535866
try this, and lets see the code, maybe you are setting one when you don't want to..

while (! (timein==0 || timeout==0))
{
  execute code....
}
0
 
LVL 16

Accepted Solution

by:
imladris earned 120 total points
ID: 2535872
I think your confusion lies in the while. The condition

timein!=0 && timeout!=0

will evaluate to true if both timein and timeout are nonzero. However, you want that to be your stopping condition. A while is defined as:

while(condition)
{   code
}

The while will continue to iterate executing code as long as condition evaluates to true.
As you can see your condition specifies when to stop, whereas the while expects it to specify the condition for continueing. So reversing it should suffice either:

while(timein==0 || timeout==0)

or

while(!(timein!=0 && timeout!=0))

0
 

Author Comment

by:drummond
ID: 2536489
You're right! Thank you!

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 175
smtp c source code 7 106
If a cell in a range equals "YES" return specific Test. 4 43
Windows Server 2012 R2 - connect to computer 13 64
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question