14 9188
coooool,, thanks
"Hans Kesting" <ne***********@ spamgourmet.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. yes
Hi there,
Any sample to do nested ternary. Interesting!
Thanks.
--
Regards,
Chua Wen Ching :)
"Josh" wrote: coooool,, thanks "Hans Kesting" <ne***********@ spamgourmet.com > wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. yes
> Any sample to do nested ternary. Interesting!
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 5;
int g = 5;
int r;
r = (a<b) ? (c<d) ? e : f : g;
It returns 5
You can nest them, but it's not usually good for readability.
Console.WriteLi ne((i < 0) ? "negative" : ((i > 0) ? "positive" :
"zero"));
P.
> You can nest them, but it's not usually good for readability.
True but Im trying to write a single expression to check for collison
between 3d objects its already a nightmare!!!
I wouldn't create such constructs at all - totally unreadable (even this is
only a sample).
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"Josh" <so*****@micros oft.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l... Any sample to do nested ternary. Interesting!
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 5;
int g = 5;
int r;
r = (a<b) ? (c<d) ? e : f : g; It returns 5
Hi,
It's kind of how you can traverse a matrix using a single for in C :)
I still remember the first time I delivered a homework with that in the
univ. the teacher gave me a 2 ( suspense in Cuba's grades ) just for that :)
It's better using two lines of code, or at least separate them in more than
one line, and use parentesis.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Josh" <so*****@micros oft.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l... Any sample to do nested ternary. Interesting!
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 5;
int g = 5;
int r;
r = (a<b) ? (c<d) ? e : f : g; It returns 5
Hi,
Then make it the most readable possible something like:
r = (a<b) ?
(c<d) ? e : f
: g;
With one condition per line, instead of all in the same line.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Josh" <so*****@micros oft.com> wrote in message
news:Ok******** ******@tk2msftn gp13.phx.gbl... You can nest them, but it's not usually good for readability. True but Im trying to write a single expression to check for collison between 3d objects its already a nightmare!!!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul E Johnson |
last post by:
Dear friends in C:
I'm completely baffled by this problem I have with
printf statements and conditional operators in C.
I'm using gcc-3.3.
I have a project where the rarely used Union type
is called for! Incredible, but true.
union mixed
|
by: Paul E Johnson |
last post by:
Dear friends in C:
I'm completely baffled by this problem I have with
printf statements and conditional operators in C.
I'm using gcc-3.3.
I have a project where the rarely used Union type
is called for! Incredible, but true.
union mixed
|
by: glongword |
last post by:
As the assert macro should evaluate to a void expression, it should
not have an 'if statement' in its definition. Does this necessitate
the existence of a ternary conditional operator? Is there a way
assert.h can be implemented without using it? Are these decisions
related in anyway?
|
by: Robert Zurer |
last post by:
In his paper on Coding Standard found on
http://www.idesign.net/idesign/DesktopDefault.aspx
Juval Lowy discourages the use of the ternary conditional operator with no
specific reason given.
I can understand that complicated code would be much less readable using nested
operators, but aside from that is there another reason? -- something going on
under the hood perhaps which make it inadvisable to use?
|
by: Daniel Crespo |
last post by:
Hi!
I would like to know how can I do the PHP ternary operator/statement
(... ? ... : ...) in Python...
I want to something like:
a = {'Huge': (quantity>90) ? True : False}
Any suggestions?
| |
by: slogging_away |
last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks
on text files, (configuration files), so discrepancies can be reported.
The script works fine but it appears that I may have hit a wall with
'if' statements.
Due to the number of checks perfromed by the script on the text files,
(over 500), there are quite a few 'if' statements in the script, (over
1150). It seems that it...
|
by: PerlPhi |
last post by:
hi,,, while ago i was wondering why do some programmers rarely uses the ternary operator. wherein it is less typing indeed. i believe in the classic virtue of Perl which is laziness. well let me show you something first before i go to my delimma.
codes as follows using Mrs. If Else:
#!perl/bin/perl
use strict;
print "Are you sure you want to quit ('yes' or any key for 'no'): ";
chomp($_ = <STDIN>);
|
by: Neil Cerutti |
last post by:
The docs say:
A suite can be one or more semicolon-separated simple statements on
the same line as the header, following the header's colon, or it can
be one or more indented statements on subsequent lines. Only the
latter form of suite can contain nested compound statements; the
following is illegal, mostly because it wouldn't be clear to which if
clause a following else clause would belong:
if test1: if test2: print x
|
by: K Viltersten |
last post by:
In the code at our company i see the following.
if (someStuff != null) {
if (someStuff != "") {
doThatThing ();
}
}
While it's fully correct and valid, i'd like to rewrite it
as follows.
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |