Differences between If Then & If Else

What's the difference between If Then & If Else and what would the different applications be? e.g. Why would I choose one over the other?

Here's how I would answer that:

If A=B then Speak "they are equal"

gives you the same result as

If A<>B then (nothing) else Speak "they are equal"

As you might guess, those fragments of code do the same thing while one of them is using "if then" while the other one is using "if else".

I prefer using the first of the two methods. I find it clearer. But they are identical.

Please forgive my ignorance, but what does <> mean?

That is the standard expression for "not equals," which is the opposite of "=". Some people prefer "≠" but since that's not a key on any keyboard, we programmers use "<>" instead. It means "less that or greater than" which is the same as "not equals."

I'm happy to answer any more questions. But it can sometimes be days before visits to these forums.

You're really asking (I think) the difference between if and if else (the then being entirely unnecessary).

So the difference is that if doesn't think twice: If I win the lottery, I'll quit my job.

But if else includes a Plan B: If I win the lottery, I'll quit my job. Otherwise, I'll go to work tomorrw.

4 Likes