Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
confusing if (condition)
Old 08-12-2007, 01:08 PM confusing if (condition)
Average Talker

Posts: 22
Trades: 0
Hi,

i've just followed an entrance test yesterday, and i got 1 question that is really confusing me.. and i think it's impossible for answering the question.
so the question is:

PHP Code:
if(condition)
{
      print 
"Hello";
}
else
{
      print 
"World";


so what is the appropriate condition to make the code above print "HelloWorld"? is it possible to print the HelloWord by modifying the condition only? i'm just curious anyway =)

thank's for your attention

Regards
moccacinoe is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-12-2007, 04:19 PM Re: confusing if (condition)
stOx's Avatar
Machine

Latest Blog Post:
Worlds Smallest Car - Peel P50
Posts: 2,111
Name: Matt. (>',')>
Location: London, England.
Trades: 0
I can't see how it would be possible.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
stOx is offline
Reply With Quote
View Public Profile Visit stOx's homepage!
 
Old 08-12-2007, 04:27 PM Re: confusing if (condition)
kosmos_world's Avatar
Novice Talker

Posts: 13
Trades: 0
It's not possible Yes or not!
That's all!
or....
PHP Code:
if(condition)
{
      echo 
"Hello";
}
elseif (new 
condition)
{
      echo 
"Hello World";

else
{
      echo 
"World";

__________________

Please login or register to view this content. Registration is FREE
kosmos_world is offline
Reply With Quote
View Public Profile Visit kosmos_world's homepage!
 
Old 08-12-2007, 04:30 PM Re: confusing if (condition)
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
If the if is only being run once then I can't see how any condition would be possible unless the condition was both true and false...maybe Schrodinger's Cat Dead....:P

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-12-2007, 05:31 PM Re: confusing if (condition)
Experienced Talker

Posts: 34
Name: Dan
Trades: 0
An if/else will execute either/or. It'll never run both over the same execution.

if ($test) {
print "Hello";
}
else {
print "World";
}

$test = 1 will print hello. $test = 0 will print world. If you need it to output both hello and world when $test = 1, you'd be better off putting both print statements under the if=true section. Unless I'm missing something. This obviously depends on your requirements.
__________________

Please login or register to view this content. Registration is FREE

1Gb hosting from as little as £1.49/€2.20/$3 /month - No kidding!
danneh3826 is offline
Reply With Quote
View Public Profile Visit danneh3826's homepage!
 
Old 08-12-2007, 06:26 PM Re: confusing if (condition)
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
For example if you get your condition from url script can look like this:

PHP Code:
$test = @$_GET['test'];

if (
$test == '1') { 
print 
"Hello"// print Hello if is set 1 
}elseif($test == '2') {
print 
"Hello World"// print Hello World if is set 2 
} else {
print 
"World"// print World if is condition empty 
                  // or any other number then 1 or 2

Shivaji
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 08-12-2007, 06:47 PM Re: confusing if (condition)
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
If the if/else were inside a loop, then you could use the same condition to print both the Hello and World

PHP Code:
for ($i 0$i 2$i++)
{
  if (
$i == 0)
  {
    echo 
'Hello';
  }
  else
  {
    echo 
'World';
  }


Otherwise you could use a switch construct to print World or HelloWorld depending if the condition was met.

PHP Code:
switch (true)
{
  case (
condition):
    echo 
'Hello';
 
  default:
    echo 
'World';

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 02:42 AM Re: confusing if (condition)
Average Talker

Posts: 22
Trades: 0
Hi... thank's a lot for the repliess..
when i read danneh3826 reply, i just remembered, if i'm not mistaken, the question stated something like this "function print always return 1 when it is executed", and i was told to not change anything besides the condition in the if (condition). maybe it just a question for testing your logic =) i don't know. however my answer for that question was "i don't think it's possible"
moccacinoe is offline
Reply With Quote
View Public Profile
 
Old 08-13-2007, 04:34 AM Re: confusing if (condition)
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
hmm, If it is in a function then simply run it twice but pass a different condition parameter and run the function twice, it seems you neglected to mention that in your first post.

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-13-2007, 08:58 AM Re: confusing if (condition)
dlaroche22's Avatar
Skilled Talker

Posts: 84
Name: Dustin Laroche
Trades: 0
Interesting......
dlaroche22 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to confusing if (condition)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.69224 seconds with 12 queries