if-condition

Avoid IF statement after condition has been met

I have a division operation inside a cycle that repeats many times. It so happens that in the first few passes through the loop (more or less first 10 loops) the divisor is zero. Once it gains value, a div by zero error is not longer possible. I have an if condition to test the divisor value in order to avoid the div by zero, but I am w...

Problem with writing if condition

I have two decimal numbers. I want those number to be same upto 4 decimal points without rounding. If numbers are different I want 2nd number to be replaced by 1st. What if condition should I write? Eg, 1. num1 = 0.94618976 num2 = 0.94620239 If we round these numbers upto 4 decimal then we get 0.9462 same number, but I don't want...

What happens if the first part of an if-structure is false?

Hey guys, I was wondering what happens when a program processes an if-structure with multiple conditions. I have an idea, but i'm not sure about it. I'll give an example : List<string> myTestList = null; if (myTestList != null && myTestList.Count > 0) { //process } The list is null. When processing the if, will it go from left t...

LINQ - if condition

In code, the commented part is what I need to solve... Is there a way to write such query in LINQ? I need this because I will need sorting based on Status. var result = ( from contact in db.Contacts join user in db.Users on contact.CreatedByUserID equals user.UserID join deal in db.Deals on contact.ContactID equals deal.C...

Does a begin-end block affect the performance of a conditional statement?

I am working with Delphi. Does it make any difference in performance if we write if condition in different ways? For example: if (condition) then someVar := someVal else someVar := someOtherVal; Or we can write: if (condition) then begin someVar := someVal; end else begin someVar := someOtherVal; end; I prefer the s...