It's good, if you don't have anything to do in else or no need or able to mange without else.
Each statement increase your execution time and also compile time.
So if you able to reduce number of statements and expressions, you saving execution time and also compile time.
let var1 = 10; // during the declaration initialise the variable, act as else variableif (condition == true) {
var1 = 20;
}
So here number of statement going to execute
if statement execute
1. declarevariableand initialize.
2.Verifyifcase3.ExecuteIfcaseblock
Total Time need (eachstatement need 1 unit) is3unit
if statement not execute
1. declarevariableand initialize
2.Executeifcase
Total Time need(eachstatement need 1 unit) is2 unit
Total statement going to be 5, one for declare variable and assign with garbage value
And number of statement going
if statement execute: Statements are
1. Declarevariable2.Executeifstatement, toevaluatetrue3.Executeif code(var1=20)
Total time need(ie: eachstatement need 1 unit) is3unit
-if statement not execute: Statement sare
1. Declarevariable2.Executeifstatement, toevaluatefalse3.Movetoelseblock4.Executeelse code(var1=10)
Total time need(ie: eachstatement need 1 unit) is4unit
It's good, if you don't have anything to do in else or no need or able to mange without else.
Each statement increase your execution time and also compile time. So if you able to reduce number of statements and expressions, you saving execution time and also compile time.
let var1 = 10; // during the declaration initialise the variable, act as else variable if (condition == true) { var1 = 20; }So here number of statement going to execute
1. declare variable and initialize. 2. Verify if case 3. Execute If case block Total Time need (each statement need 1 unit) is 3unit1. declare variable and initialize 2. Execute if case Total Time need(each statement need 1 unit) is 2 unitNow consider following code
if (condition == true) { var1 = 20; } else { var1 = 10; }Total statement going to be 5, one for declare variable and assign with garbage value
And number of statement going
1. Declare variable 2. Execute if statement, to evaluate true 3. Execute if code(var1=20) Total time need(ie: each statement need 1 unit) is 3unit-if statement not execute: Statement sare
1. Declare variable 2. Execute if statement, to evaluate false 3. Move to else block 4. Execute else code(var1=10) Total time need(ie: each statement need 1 unit) is 4unit