473,657 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple question regarding If and bools.... just to clear any doubts I have!

VMI
I'm having doubts as to how the compiler interprets this If statement:

bool bIsTrue = true;

if (! bIsTrue)
{
//RUN PROCESS
}

Here, will "RUN PROCESS" be executed? Or is this just wrong? How is this
really interpreted by the compiler?

Thanks.
Nov 17 '05 #1
2 1301
Read it like this

if (not True)
//RUN PROCESS

....same as...
if(bIsTrue == false)
//RUN PROCESS

"VMI" <vo******@yahoo .com> wrote in message
news:OD******** *******@tk2msft ngp13.phx.gbl.. .
I'm having doubts as to how the compiler interprets this If statement:

bool bIsTrue = true;

if (! bIsTrue)
{
//RUN PROCESS
}

Here, will "RUN PROCESS" be executed? Or is this just wrong? How is this
really interpreted by the compiler?

Thanks.

Nov 17 '05 #2
Hi VMI,
the if statement will enter the if section only if the conditional
statement evaluates to true.

so if you write:

if(true)
{
//will always come here
}
else
{
//will never get here
}

the top section will always get entered because the conditional always
evaluates to true. Conversely if you write:

if(false)
{
//will never go here
}
else
{
//will always go here
}

the if statement always evaluates to false, so the else will always be
entered.

So for your code:
bool bIsTrue = true;

if (! bIsTrue)
{
//RUN PROCESS
}
this is really saying:

if(NOT TRUE)
{
}

which is equivalent to

if(FALSE)
{
//will never go here
}
Hope that helps
Mark R Dawson
http://www.markdawson.org

"VMI" wrote:
I'm having doubts as to how the compiler interprets this If statement:

bool bIsTrue = true;

if (! bIsTrue)
{
//RUN PROCESS
}

Here, will "RUN PROCESS" be executed? Or is this just wrong? How is this
really interpreted by the compiler?

Thanks.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2143
by: JC | last post by:
Hi - I'm currently learning PHP using the ORA "cuckoo" book. I'm looking for some reasonably interesting sample code to read and thought that a *simple* Wiki could be ideal. Can anyone recommend a Wiki which implements the basic functionality only to keep things simple, written in nice clear PHP code? I'm hoping that a couple of hundred lines or less of PHP will suffice to get a basic wiki running, without resorting to obfusticated...
6
1575
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was that once you compile a C program the executable created is all that is needed whereas if you compile a C++ program the executable created requires a C++ runtime installed on your system to run the program. Can someone please provide more...
5
2015
by: Davie | last post by:
I'm developing an application on the smartphone. To reduce the size of the application i'm using panels where appropriate instead of forms. As a result of the design, I need to have different context menus on one form. I had tried to declare two MainMenu items and then simply switch the display accordingly. eg. public void displayPanel1(){ this.Menu = this.mainMenu1; // this.Refresh(); } public void displayPanel2(){ this.Menu =...
18
3152
by: Frances | last post by:
I want to learn PHP.. I know JSP, Servlets, have been using Tomcat for 2 years now, and even though I know there are ways you can use PHP in conjunction with Tomcat, I'd rather not tinker with Tomcat.. I think I'd rather try to do it straight 'from scratch'... following instructions here, http://us2.php.net/tut.php.. so you need both Apache **AND** PHP server? not sure what to dl when get to http://www.apache.org/ (HTTP Server? top...
4
10274
by: Russell Warren | last post by:
I'm guessing no, since it skips down through any Lock semantics, but I'm wondering what the best way to clear a Queue is then. Esentially I want to do a "get all" and ignore what pops out, but I don't want to loop through a .get until empty because that could potentially end up racing another thread that is more-or-less blindly filling it asynchronously. Worst case I think I can just borrow the locking logic from Queue.get and clear...
0
2339
by: derelict | last post by:
Hey all, im getting desperate now. I have a macro running in Word 2003, when I run the macro it *should* put a 'bottom' cell border in each cell that has the style used - this included a border at the top of the table and one at the bottom, like a set of container border for a table with no border within it. i.e table heading _______________________________ << top border text in the table spanning multiple rows and columns...
5
2104
by: Michael Goldshteyn | last post by:
Consider the following two lines of code, the first intended to print "Hello world\n" and the second intended to print the character 'P' to stdout. --- std::cout << static_cast<std::ostringstream &>(std::ostringstream() << "Hello world\n").str(); std::cout << static_cast<std::ostringstream &>(std::ostringstream() << 'P').str(); ---
2
1218
by: jonKushner | last post by:
So, after the long debate about using ANY sort of external packaged library besides my own hacked scripts, I decided to dig through the source code of ZF and peek around. I was pretty impressed. It reminded me a whole heap of college, specifically with Java and the zillions of classes I would build with eclipse :) Here's what I liked : 1/ Singleton patterns - Neat. I can see how this is quite resourceful.
4
1559
by: samuel123 | last post by:
Greetings All, Once again back to this forum. I have got a problem and hope to get solution. Senario.. I have a table called users, it has following fields user_name firstname lastname ---------------- -------------- ------------- Parker Alan & Jenny Parker
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.