473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Difference between if if and if if else

Hi. What is the difference between

if {}
if {}

if {}
if else {}

?
Dec 23 '07 #1
6 9434
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....@student.uts.edu.auwrote:
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....@student.uts.edu.auwrote:
>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
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
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
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. ...
28
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...
23
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...
1
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...
6
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...
15
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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 projectplanning, coding, testing,...
0
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...

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.