DotDragnet
February 08, 2012, 10:44:46 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the new trading eye refugees
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: PHP Query  (Read 463 times)
Charisma Bypass
Hero Member
*****
Posts: 512



View Profile Awards
« on: February 12, 2010, 05:49:06 PM »

Another problem I am struggling with...

I have a $count =0.  I use $count ++;

If ($count == 0) echo "STARTING";

The $count is open ended. 

What I need to do is at the end of the $count, echo "ENDING";

Any ideas?  Thanks in advance.

Logged
neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« Reply #1 on: February 12, 2010, 05:57:54 PM »

erm, what value are you tesing $count against..?


for argument's sake let's say you're using a for loop testing $count against a value of 10:

there are a couple of ways of doing the same thing.

Code:
$end = 10;

for($count = 0; $count < $end; $count++) {

if($count == 0) echo "STARTING";

// other code to run

if($count == $end) echo "ENDING";
}

otherwise:

Code:
$end = 10;

echo "STARTING";

for($count = 0; $count < $end; $count++) {

// code to run here

}

echo "ENDING";


the second way would be _slightly_ faster because you're not testing for the value of $count an extra 2 times on each loop but the code isn't quite as modular & pretty. i hate having random echo statements each side of loops throughout the code.
Logged

sig edited due to migrating from .net
Charisma Bypass
Hero Member
*****
Posts: 512



View Profile Awards
« Reply #2 on: February 13, 2010, 06:09:27 PM »

D'oh.  thanks Neal, you rescued me from head bashing keyboard.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!