Raised This Month: $51 Target: $400
 12% 

Solved What si better


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 12-26-2016 , 18:12   What si better
Reply With Quote #1

One simple question

Is better use
PHP Code:
If(variable 1//some code;
else if(variable 0//some code; 
or this
PHP Code:
(variable //some code// : //some code//); 
__________________

Last edited by _GamerX; 12-26-2016 at 19:56.
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
JOMENVEST
Member
Join Date: Dec 2016
Location: Sweden
Old 12-26-2016 , 18:22   Re: What si better
Reply With Quote #2

Maybe like this?
PHP Code:
if (variable == 1
{
//some code;

}
else 
{
//some code;  



Last edited by JOMENVEST; 12-26-2016 at 18:36.
JOMENVEST is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 12-26-2016 , 18:32   Re: What si better
Reply With Quote #3

Quote:
Originally Posted by JOMENVEST View Post
Maybe like this?
PHP Code:
if (variable == 1) /
{
//some code;

}
else 
{
//some code;  


-_-
__________________
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
thecount
Veteran Member
Join Date: Jul 2013
Old 12-26-2016 , 19:30   Re: What si better
Reply With Quote #4

Depends on how much code you want to implement. It's really just a choice in how it is displayed.
thecount is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 12-26-2016 , 19:39   Re: What si better
Reply With Quote #5

Its up to you I use the second one you mentioned for multiple conditions like

Code:
(varable == true? (variable == true? (variable == true?"True":"False"):"False"):"False")
It takes much less space then if, else if or else

In other cases where is just one variable i use switch and so..
ESK0 is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 12-26-2016 , 19:55   Re: What si better
Reply With Quote #6

Quote:
Originally Posted by ESK0 View Post
Its up to you I use the second one you mentioned for multiple conditions like

Code:
(varable == true? (variable == true? (variable == true?"True":"False"):"False"):"False")
It takes much less space then if, else if or else

In other cases where is just one variable i use switch and so..
Thanks
__________________
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
sahapro33
Member
Join Date: Mar 2014
Old 12-27-2016 , 04:02   Re: What si better
Reply With Quote #7

Lol ;D
PHP Code:
public void OnPluginStart()
{
    
bool variable true;
    
PrintToServer((variable == true? (variable == true? (variable == true?"True":"False"):"False"):"False"));

==
PHP Code:
public void:OnPluginStart()
{
    new 
bool:variable 1;
    new 
var3;
    if (
variable == true)
    {
        new 
var2;
        if (
variable == true)
        {
            new 
var1;
            if (
variable == true)
            {
                
var1 2268;
            }
            else
            {
                
var1 2276;
            }
            
var2 var1;
        }
        else
        {
            
var2 2284;
        }
        
var3[0] = var2;
    }
    else
    {
        
var3[0] = 2292;
    }
    
PrintToServer(var3);
    return 
void:0;


Last edited by sahapro33; 12-27-2016 at 04:02.
sahapro33 is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 12-27-2016 , 06:17   Re: What si better
Reply With Quote #8

Quote:
Originally Posted by sahapro33 View Post
[...]
Umm, whut???
cravenge is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 12-27-2016 , 11:16   Re: What si better
Reply With Quote #9

Quote:
Originally Posted by sahapro33 View Post
Lol ;D
PHP Code:
public void OnPluginStart()
{
    
bool variable true;
    
PrintToServer((variable == true? (variable == true? (variable == true?"True":"False"):"False"):"False"));

==
PHP Code:
public void:OnPluginStart()
{
    new 
bool:variable 1;
    new 
var3;
    if (
variable == true)
    {
        new 
var2;
        if (
variable == true)
        {
            new 
var1;
            if (
variable == true)
            {
                
var1 2268;
            }
            else
            {
                
var1 2276;
            }
            
var2 var1;
        }
        else
        {
            
var2 2284;
        }
        
var3[0] = var2;
    }
    else
    {
        
var3[0] = 2292;
    }
    
PrintToServer(var3);
    return 
void:0;

I said it takes much less space
ESK0 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 12-27-2016 , 11:25   Re: What si better
Reply With Quote #10

Quote:
Originally Posted by sahapro33 View Post
Lol ;D
PHP Code:
public void OnPluginStart()
{
    
bool variable true;
    
PrintToServer((variable == true? (variable == true? (variable == true?"True":"False"):"False"):"False"));

==
PHP Code:
public void:OnPluginStart()
{
    new 
bool:variable 1;
    new 
var3;
    if (
variable == true)
    {
        new 
var2;
        if (
variable == true)
        {
            new 
var1;
            if (
variable == true)
            {
                
var1 2268;
            }
            else
            {
                
var1 2276;
            }
            
var2 var1;
        }
        else
        {
            
var2 2284;
        }
        
var3[0] = var2;
    }
    else
    {
        
var3[0] = 2292;
    }
    
PrintToServer(var3);
    return 
void:0;

I'd prefer if you're going to publicly display the code you atleast make it readable, making it one line can make the code look messy. I would rather see the second of expanding statements.
Mitchell is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 02:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode