What is wrong with my if-statement?

; is not allowed before else in the majority of cases. if ((input=”y”) or (input=”Y”)) then begin writeln (‘blah blah’); end else if ((input=”n”) or (input=”N”)) then begin writeln (‘blah’); end else begin writeln (‘Input invalid!’); end; will compile. But… Prefer using begin … end brackets to avoid misunderstanding of code in complicated if then … Read more

Is returning early from a function more elegant than an if statement?

In most cases, returning early reduces the complexity and makes the code more readable. It’s also one of the techniques applied in Spartan programming: Minimal use of Control Minimizing the use of conditionals by using specialized constructs such ternarization, inheritance, and classes such as Class Defaults, Class Once and Class Separator Simplifying conditionals with early … Read more

weird results with IF

The reason for this result can be found in documentation of function strtol which is used first on using the comparison operators EQU, NEQ, LSS, LEQ, GTR, GEQ as explained in my answer on Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files. Return Value On success, the function returns the converted integral … Read more

VB6 IIf advantage

IIf is not an operator or a language construct, it’s a function, just like any other function such as Left. It will therefore evaluate all its arguments at all times, whereas with If you will only evaluate the correct branch. Example: denominator = 0 value = IIf(denominator = 0, 0, value / denominator) This will … Read more

How is Swift `if let` evaluated?

Essentially the line is saying, “if you can let the new variable name equal the non-optional version of optionalName, do the following with it”. As Martin pointed out, this is called Optional Binding. The sole purpose of it is to test if an optional variable contains an actual value and bind the non-optional form to … Read more