how do u use the conditions, like if u want a program to locate a file, it will say file found and if not there, it will say not found?
thnx
how do u use the conditions, like if u want a program to locate a file, it will say file found and if not there, it will say not found?
thnx
It depends on the function.
For example:
bool Init();
if (!Init)
The exclamation means if init returns zero: then do something.
Heres some more:
&& e.g: if (init && unit)
which means if init and unit are true:
|| e.g: if (init || unit)
which means if either init or unit is true:
Last edited by jimboob; 12-06-2004 at 12:55 AM. Reason: Accidently pressed on submit after not realising tab didn't work
You have to CALL the function, jimboob.
There are four statements that have a condition, if, while, do...while and for
if(condition)
while(condition)
do ... while(condition)
for( ; condition ; )
The condition is just any kind of expression that can be converted to the bool type, which is a single boolean value (true/false logic). This means it may be directly a bool (bool variable, bool function return value, result of the comparison and logical operators <, >, <=, >=, ==, !=, &&, ||, !) or something convertible. All numbers (floats and integers alike) can be converted to bool using a simple rule: non-zero is true, zero is false. Pointers can be converted to bool, too. Non-null is true, null is false. You can define boolean conversions for your classes yourself.
The comparison operators work just like you'd expect them to. > is greater-than, < is less-than. >= is greater-than-or-equal-to, <= less-than-or-equal-to. == is equal-to and != is not-equal-to.
The logical operators are simple, too. && is logical AND, both sides must be true in order for the whole to be true. || is logical OR, both sides must be false in order for the whole to be false. ! is logical NOT, it flips the operand.
&& and || are lazy. They evaluate the right-hand-side only if it is required to determine the result. In (a && b), if a is false, then b is never evaluated. Similarly, in (a || b), if a is true, then b is never evaluated.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I doubt you will find someone willing to write up some code in this manner. You will more than likely find a similar example in some of the C/ C++ tutorials on the web. There's a nice set of tutorials right here at cprogramming.com (link on the main page), and you'll surely be able to find hundreds more at Google. Right now however, the tutorials on this site should be sufficient for your needs - give them a try.
edit:
WARNING - The last time I visited this page my PC was temporarily paralyzed by well over a hundred pop-up ads. I'm not sure if this is more than a once-off problem, but I would definately open this link in a browser enabled with Pop-Up Blocker if convenient to avoid any potential hassle.
Nevertheless, here's a link to this site's tutorial page.
http://www.cprogramming.com/tutorial.html
Last edited by sean; 12-06-2004 at 09:48 PM.