Hi,
in the program below, what is the meaning/use of
the question mark (?gcd) and the colon (:$a) after the return statement? Any
explanation will be appreciated.
<?
$x=32;
$y=80;
function gcd($a, $b)
{ return ($b>0)?gcd($b,$ a%$b):$a;}
$val=gcd($x, $y);
print "The greatest common denominator of $x and $y is $val";
?>
This recursive program is used to find the greatest common denominator of 2
numbers.
TIA 9 1569
Michael Jack wrote: Hi,
in the program below, what is the meaning/use of the question mark (?gcd) and the colon (:$a) after the return statement? Any explanation will be appreciated.
Hi Michael,
It is just a shorthand notation for an if-then-else statement
eg:
$a = 10;
echo ( ($a<20) ? "$a is smaller then 20!" : "$a is not smaller then 20!");
is the same as:
$a = 10;
if ($a<20) {
echo "$a is smaller then 20!";
} else {
echo "$a is not smaller then 20!";
}
Regards,
Erwin Moller <? $x=32; $y=80; function gcd($a, $b) { return ($b>0)?gcd($b,$ a%$b):$a;} $val=gcd($x, $y); print "The greatest common denominator of $x and $y is $val"; ?>
This recursive program is used to find the greatest common denominator of 2 numbers.
TIA
Many thanks.
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:43******** *************** @news.xs4all.nl ... Michael Jack wrote:
Hi,
in the program below, what is the meaning/use of the question mark (?gcd) and the colon (:$a) after the return statement? Any explanation will be appreciated.
Hi Michael,
It is just a shorthand notation for an if-then-else statement
eg: $a = 10; echo ( ($a<20) ? "$a is smaller then 20!" : "$a is not smaller then 20!");
is the same as: $a = 10; if ($a<20) { echo "$a is smaller then 20!"; } else { echo "$a is not smaller then 20!"; }
Regards, Erwin Moller
<? $x=32; $y=80; function gcd($a, $b) { return ($b>0)?gcd($b,$ a%$b):$a;} $val=gcd($x, $y); print "The greatest common denominator of $x and $y is $val"; ?>
This recursive program is used to find the greatest common denominator of 2 numbers.
TIA
Erwin Moller said the following on 11/10/2005 10:05: Michael Jack wrote:
Hi,
in the program below, what is the meaning/use of the question mark (?gcd) and the colon (:$a) after the return statement? Any explanation will be appreciated.
Hi Michael,
It is just a shorthand notation for an if-then-else statement
Not quite. You couldn't use it for something like:
if (6 == $a)
{
for ($i = 0; $i < $a; ++i)
{
...
}
}
else
{
// Some other code
}
It's really a conditional assignment operator.
--
Oli
Many thanks for the prompt reply.
Regards,
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:43******** *************** @news.xs4all.nl ... Michael Jack wrote:
Hi,
in the program below, what is the meaning/use of the question mark (?gcd) and the colon (:$a) after the return statement? Any explanation will be appreciated.
Hi Michael,
It is just a shorthand notation for an if-then-else statement
eg: $a = 10; echo ( ($a<20) ? "$a is smaller then 20!" : "$a is not smaller then 20!");
is the same as: $a = 10; if ($a<20) { echo "$a is smaller then 20!"; } else { echo "$a is not smaller then 20!"; }
Regards, Erwin Moller
<? $x=32; $y=80; function gcd($a, $b) { return ($b>0)?gcd($b,$ a%$b):$a;} $val=gcd($x, $y); print "The greatest common denominator of $x and $y is $val"; ?>
This recursive program is used to find the greatest common denominator of 2 numbers.
TIA
"Michael Jack" <mi*****@jack20 05.com> writes: Hi,
in the program below, what is the meaning/use of the question mark (?gcd) and the colon (:$a) after the return statement? Any explanation will be appreciated.
<? $x=32; $y=80; function gcd($a, $b) { return ($b>0)?gcd($b,$ a%$b):$a;} $val=gcd($x, $y); print "The greatest common denominator of $x and $y is $val";
You have stumbled on the ternary operator;
But the real reason for this is to obfuscate the program and confuse
everyone who reads it!
No kidding. I quit using ?: years ago and prefer the more verbose
if/then/else. Others may disagree.
HTH
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Oli Filth wrote: Erwin Moller said the following on 11/10/2005 10:05: Michael Jack wrote:
Hi,
in the program below, what is the meaning/use of the question mark (?gcd) and the colon (:$a) after the return statement? Any explanation will be appreciated.
Hi Michael,
It is just a shorthand notation for an if-then-else statement
Not quite. You couldn't use it for something like:
if (6 == $a) { for ($i = 0; $i < $a; ++i) { ... } } else { // Some other code }
It's really a conditional assignment operator.
True.
:-)
Regards,
Erwin Moller
In article <xY************ ******@newsfe6-win.ntli.net>,
Oli Filth <ca***@olifilth .co.uk> wrote: It's really a conditional assignment operator.
But it isn't an assignment operator.
-- http://yosemitecampsites.com/ el***@no.spam said the following on 11/10/2005 18:34: In article <xY************ ******@newsfe6-win.ntli.net>, Oli Filth <ca***@olifilth .co.uk> wrote:
It's really a conditional assignment operator.
But it isn't an assignment operator.
Good point.
--
Oli
Oli Filth wrote: el***@no.spam said the following on 11/10/2005 18:34: In article <xY************ ******@newsfe6-win.ntli.net>, Oli Filth <ca***@olifilth .co.uk> wrote:
It's really a conditional assignment operator.
But it isn't an assignment operator.
Good point.
Slowly but surely we are getting there!
;-)
Regards,
Erwin Moller This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike |
last post by:
I am sure that I am making a simple boneheaded mistake and I would
appreciate your help in spotting in. I have just installed
apache_2.0.53-win32-x86-no_ssl.exe
php-5.0.3-Win32.zip
Smarty-2.6.7.tar.gz
on a system running WindowsXP SP2.
Apache and PHP tested out fine. After adding Smarty, I ran the
following http://localhost/testphp.php
|
by: edgrsprj |
last post by:
PROPOSED EARTHQUAKE FORECASTING
COMPUTER PROGRAM DEVELOPMENT EFFORT
Posted July 11, 2005
My main earthquake forecasting Web page is:
http://www.freewebz.com/eq-forecasting/Data.html
Newsgroup Readers: If you circulate copies of this report to groups of
computer programmers at different universities etc. around the world then
they might find the subject matter to be interesting.
|
by: Tom Lee |
last post by:
Hi,
I'm new to .NET 2003 compiler. When I tried to compile my
program using DEBUG mode, I got the following errors in the
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
\include\xdebug file as folows. I need help to resolve
them ASAP:
cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D "
WIN32" /D "_W
INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
|
by: christopher diggins |
last post by:
I am wondering if any can point me to any open-source library with program
objects for C++ like there is in Java? I would like to be able to write
things like
MyProgram1 >> MyProgram2 >> Fork(MyProgram3, SomeFile);
If not would this be something of interest to others?
Thanks in advance,
|
by: Eric Whittaker |
last post by:
hi all,
im trying to write my first c++ program. a success, but i can't get the
window to stay open after user enters input. it just automatically closes.
right now the end of my program looks like this:
return 0;
}
| |
by: Hemal |
last post by:
Hi All,
I need to know the memory required by a c program. Is there any
tool/utility which can give me the memory usage in terms of DATA
segment, TEXT segment, BSS segment etc.
I am working on linux platform and my target is ARM processor. But i
guess it should not matter. Actually i need to know both RAM & ROM
usage.
|
by: ibtc209 |
last post by:
I just started programming in C, and I need some help with this problem.
Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s
first card, and the rank and suit of its second card. Note that the two cards in a hand may be entered in
any order; it’s not necessarily the case that the highest card will appear first, for example. Your program will
then determine whether the hand is valid, and...
|
by: Banfa |
last post by:
Posted by Banfa
The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how we set about doing that.
Every program starts with a specification, this may be a several hundred page document from your latest client or one small paragraph from your professor and pretty much anything in-between.
The specification is very...
|
by: amitpatel66 |
last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations:
Concurrent programs can be executed programatically either from UNIX or Oracle PLSQL. In this Section, I will be explaining about calling a Concurrent program from UNIX using the CONCSUB Command.
Pre-requisite:
1. Concurrent Program should be registered in oracle Applications...
|
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: 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,...
| |
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: 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...
|
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.
| |
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...
| |