473,836 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between if if and if if else

Hi. What is the difference between

if {}
if {}

if {}
if else {}

?
Dec 23 '07 #1
6 9453
Sun, 23 Dec 2007 10:34:54 +0000에, Logan Lee 썼습니다:
Hi. What is the difference between

if {}
if {}

if {}
if else {}

?
I meant else if and not if else.
Dec 23 '07 #2
On Dec 23, 12:36 pm, Logan Lee <logan.w....@st udent.uts.edu.a uwrote:
Sun, 23 Dec 2007 10:34:54 +0000, Logan Lee ϴ:
Hi. What is the difference between
if {}
if {}
if {}
if else {}
?

I meant else if and not if else.

if( g() == -1 ) {
/* ... */
} else if( h() == -1) {
/* ... */
}

Both g and h write to stdout, but h will be called ONLY if g returns
-1.
Dec 23 '07 #3
Logan Lee wrote:
Sun, 23 Dec 2007 10:34:54 +0000에, Logan Lee 썼습니다:
>Hi. What is the difference between

if {}
if {}

if {}
if else {}

?

I meant else if and not if else.
Let's write something that more closely resembles legal C code:

A:
if (condition1) { statements1;}
if (condition2) { statements2;}

B:
if(condition1) {statement1;}
else if(condition2) {statements2;}

To keep this simple, I'm using statements1 and statments to each
represent a series of statements that doesn't include a return
statement, and doesn't directly or indirectly call exit(), abort(), or
longjmp().

The difference between A: and B: is that in A:, condition2 is evaluated
regardless of what condition1 is; in B:, condition2 is evaluated only if
condition1 compares equal to 0. In A:, statements2 are always executed
if condition2 does not compare equal to 0, regardless of what condition1
is. In B:, statements2 are only executed if condition1 compares equal to
0 and condition two does not compare equal to 0.


Dec 23 '07 #4
Logan Lee wrote:
>
Hi. What is the difference between

if {}
if {}

if {}
if else {}

?
The relationship between "if" and "else" is
not usually described in terms of differences and similarities.
An else statement can only occur
imediately following an if statement.
The else statement is executed if and only if
the condition for the preceding if statement evaluates to zero.

--
pete
Dec 23 '07 #5
On Sun, 23 Dec 2007 10:34:54 +0000, Logan Lee wrote:
Hi. What is the difference between

if {}
if {}

if {}
if else {}
This isn't a C question, its a simple logic question. Why not think the
logic through, instead of sitting with your brain in neutral?

Dec 23 '07 #6
vi******@gmail. com wrote:
On Dec 23, 12:36 pm, Logan Lee <logan.w....@st udent.uts.edu.a uwrote:
>Sun, 23 Dec 2007 10:34:54 +0000?, Logan Lee ????:
Hi. What is the difference between
if {}
if {}
if {}
if else {}
?

I meant else if and not if else.


if( g() == -1 ) {
/* ... */
} else if( h() == -1) {
/* ... */
}

Both g and h write to stdout, but h will be called ONLY if g returns
-1.
Only if g does not return -1.

Dec 23 '07 #7

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

Similar topics

3
3023
by: Anoj Kumar | last post by:
Hi All , can anyone tell me what is the difference between the following declaration and how it affects application performance. 1. Dim cn As ADODB.Connection Set cn = New ADODB.Connection
3
8440
by: kai | last post by:
Hi, All What is the the difference between If and #If? I read some VB.NET books, sometimes I see #If, but cannot tell why. Please help. Thanks Kai
5
5856
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. Thanks kai
28
72598
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
23
14078
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that didn't work (the timedelta class doesn't have a year accessor). I looked in the docs and the cookbook, but I couldn't find anything, so
1
1251
by: cashdeskmac | last post by:
Can anyone tell me the difference between these two xml files: <?xml version="1.0" ?> <Bookshop> <book title="my first book" author="someone"/> <book title="another book" author="someone else"/> <DVD title="how to cook" director="TV Chef"/> <DVD title="Gardening" director="TV gardener"/> </Bookshop>
6
8788
by: akk003 | last post by:
Hello I'am a returning coder to C programming language and would appreciate if you could help me understand why does my while loop behave normally in the following code: int loop = 1; char userIN; while(loop) { printf("\nIf you want to retrieve tuples prompt y/n: \t"); //items_read = scanf("%s",&userIN);
15
6450
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but but that only gave me difference in hours and only if the times were on the same day (after wrapping with date() function). TIA
11
12135
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my code is just returning me an array of 0's
0
9825
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10852
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
10599
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
10257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6980
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
5651
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
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.