Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1802 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

do NOT use {} for single if-else statements..

Thread title: do NOT use {} for single if-else statements..
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
02-18-2007, 10:53 PM
#1
Ali is offline Ali
Status: Junior Member
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Ali is on a distinguished road

  Old  do NOT use {} for single if-else statements..

hey mates, just browsed a couple of threads in this section and I got impression that most of the people are using wrong code/technique while using if or else statements..

for example if you are using "if" statement

if($x == 10) {

echo "it is 10";

} else {

echo"it is not 10";
}

now thats not a good approach since you have only one function being used in "if" and also in "else", so there is no need of using those brackets, you can use it someting like this..

if($x == 10)
echo "it is 10";
else
echo"it is not 10";

OR use ternary operator, e.g.

$myVar = condition ? if_condition_true : if_condition_false

thats just a note for beginners, since I found a couple of threads and saw their code, I though since they read these forums, it would be a good advice for beginners...

cheers

     


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed