To assign empty, or suppress error

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

To assign empty, or suppress error

Post by Joel » Thu Jul 24, 2003 8:33 pm

I'm wondering how the common way of doing something in a loop is. As in, you have a loop which adds values to a string, something like...

Code: Select all

for ($i = 0, $i < 20, $++) {
    $string .= "new value number: ".$i;
}

Would you suppress the error or assign an empty value to $string, like...

Code: Select all

$string = "";

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Post by swirlee » Fri Jul 25, 2003 5:40 am

Whenever possible, you should try to prevent an error rather than suppressing it. So yes, set your variable to an empty string before you enter the loops.

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Post by Joel » Fri Jul 25, 2003 2:19 pm

Thats how I've been doing it, it does kind of feel stupid having to do it though, especially when it works anyway.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest