PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Sep 19, 2017 8:22 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Nov 23, 2013 3:39 am 
Offline
Forum Newbie

Joined: Tue Nov 05, 2013 11:08 pm
Posts: 4
Hello,

Herebelow, I have mentioned the code of Fibonacci series : 1 10 2 9 3 8 4 7 5 6:


Syntax: [ Download ] [ Hide ]
$j=11;
for($i=1;$i<=5;$i++)
{
        $j--;
        if($j<=6)
        {
        }
        echo "$i $j ";
}
 


Can we perform the same program with other loops? If yes, then describe.


Top
 Profile  
 
PostPosted: Sat Nov 23, 2013 4:26 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6545
Location: WA, USA
Sure. for, foreach, while, do/while... They're all mostly interchangeable. They all have an initialization phase (set up variables), a conditional phase (whether to continue executing), and an advancement phase (what to do before the next loop starts). The series you're printing out can be done any one of a billion ways.

But that's not the Fibonacci series.


Top
 Profile  
 
PostPosted: Sun Nov 24, 2013 9:47 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13427
Location: New York, NY, US
Syntax: [ Download ] [ Hide ]
        if($j<=6)
        {
        }

:drunk:

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sun Nov 24, 2013 11:15 pm 
Offline
DevNet Resident

Joined: Sun Jun 14, 2009 3:13 pm
Posts: 1146
Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... :drunk:


Top
 Profile  
 
PostPosted: Mon Nov 25, 2013 12:02 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6545
Location: WA, USA
Party!

:drunk:


Top
 Profile  
 
PostPosted: Sat Jun 18, 2016 9:02 am 
Offline
Forum Newbie

Joined: Sat Jun 18, 2016 8:41 am
Posts: 1
Can we do this question with only one varible


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group