# If ....... Then

**URL:** <https://forum.xojo.com/t/if-then/66382>\
**Category:** General\
**Created:** [November 1, 2021, 1:17pm UTC](https://forum.xojo.com/t/if-then/66382 "2021-11-01T13:17:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Rongen1](https://forum.xojo.com/user_avatar/forum.xojo.com/joost_rongen1/32/15052_2.png) [@Joost\_Rongen1](https://forum.xojo.com/u/Joost_Rongen1)\
**Post date:** [November 1, 2021, 1:17pm UTC](https://forum.xojo.com/t/if-then/66382/1 "2021-11-01T13:17:03Z")

</div>

Gradually I understand less and less the meaning of the keyword **then** in if then statements. And I often forget to type it, since I doesn’t feel logic anymore.

If a = 5 Then  
…  
End if

Why not

If a = 5  
…  
End if

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [November 1, 2021, 1:36pm UTC](https://forum.xojo.com/t/if-then/66382/2 "2021-11-01T13:36:33Z")

</div>

+1 😊

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [November 1, 2021, 1:48pm UTC](https://forum.xojo.com/t/if-then/66382/3 "2021-11-01T13:48:16Z")

</div>

Did you know you could hit shift-return after the condition and it will fill in the rest for you?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [November 1, 2021, 2:10pm UTC](https://forum.xojo.com/t/if-then/66382/4 "2021-11-01T14:10:34Z")

</div>

There’s

```auto
If a > 1 Then b = c * a // one-liner case

```

The “Then” marks the end of the evaluation and the start of the execution

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [November 1, 2021, 2:30pm UTC](https://forum.xojo.com/t/if-then/66382/5 "2021-11-01T14:30:13Z")

</div>

What about `Select Case` ?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [November 1, 2021, 2:36pm UTC](https://forum.xojo.com/t/if-then/66382/6 "2021-11-01T14:36:29Z")

</div>

Just semantically better to read

**Select Case** _testExpression_  
[**Case** [ **Is**] _expression-n_ [_statements-n_]  
**Else or Case Else**  
_elseStatements_]  
**End** [**Select**]

---

<div class="post-metadata">

**Author:** ![Joost\_Rongen1](https://forum.xojo.com/user_avatar/forum.xojo.com/joost_rongen1/32/15052_2.png) [@Joost\_Rongen1](https://forum.xojo.com/u/Joost_Rongen1)\
**Post date:** [November 1, 2021, 2:55pm UTC](https://forum.xojo.com/t/if-then/66382/7 "2021-11-01T14:55:35Z")

</div>

Yes Kem, I know and use that shortcut, but it’s simply not in my nature anymore to add a THEN. Sometimes I accidently type a { instead. 🙂

---

<div class="post-metadata">

**Author:** ![Joost\_Rongen1](https://forum.xojo.com/user_avatar/forum.xojo.com/joost_rongen1/32/15052_2.png) [@Joost\_Rongen1](https://forum.xojo.com/u/Joost_Rongen1)\
**Post date:** [November 1, 2021, 2:56pm UTC](https://forum.xojo.com/t/if-then/66382/8 "2021-11-01T14:56:45Z")

</div>

> [@Rick\_Araujo](#):
>
> The “Then” marks the end of the evaluation and the start of the execution

I know, but there is simply no need for it if you continue on next line

---

<div class="post-metadata">

**Author:** ![Alexander\_Slatina](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Alexander\_Slatina](https://forum.xojo.com/u/Alexander_Slatina)\
**Post date:** [November 1, 2021, 2:59pm UTC](https://forum.xojo.com/t/if-then/66382/9 "2021-11-01T14:59:11Z")

</div>

If we compare “If … Then” to other programming languages, for example PHP, you can clearly see that we need it.

For example:

```auto
if(x > 5) 
{

}

```

In this case the closing bracket “)” marks the end of the condition. That’s why we need “Then” in Xojo language.

“Then” is useful for one-liners, for example: `If x > 5 Then App.execute(blah) End If”`  
Sometimes you want to use short one-liners.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [November 1, 2021, 3:06pm UTC](https://forum.xojo.com/t/if-then/66382/10 "2021-11-01T15:06:46Z")

</div>

Not necessarily. Many languages can omit these open and close tokens, and it’s all in how the language is designed. Take JavaScript, for example, which uses semicolon as the line token. You can do a one-line if:

```auto
if (a > b) return "a is greater";

```

Or do the same in two lines:

```auto
if (a > b)
  return "a is greater";

```

Or with the traditional curly brace tokens:

```auto
if (a > b) {
  return "a is greater";
}

```

It’s certainly feasible that Xojo could add EOL as a token in these scenarios, I’m just not sure the gain is worth the trouble. I, personally, catch myself leaving off the “Then” on conditional statements from time-to-time as I work in other languages quite a bit, but I don’t think removing the “Then” requirement is a solution any more than I want to see curly braces and semicolons in Xojo code.

---

<div class="post-metadata">

**Author:** ![Alexander\_Slatina](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Alexander\_Slatina](https://forum.xojo.com/u/Alexander_Slatina)\
**Post date:** [November 1, 2021, 3:10pm UTC](https://forum.xojo.com/t/if-then/66382/11 "2021-11-01T15:10:07Z")

</div>

Yes that is because you have the closing bracket! → “)”

If you wouldn’t have the closing bracket, the code wouldn’t work. It would throw an error.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [November 1, 2021, 3:11pm UTC](https://forum.xojo.com/t/if-then/66382/12 "2021-11-01T15:11:05Z")

</div>

> [@Joost\_Rongen1](#):
>
> there is simply no need for it if you continue on next line

Style and options.

I do prefer to write a terse:

```auto
If theWindow.NeedsLayoutWorkarounds() Then theWindow.FixTheLayout()

```

Than a 3 lines:

```auto
If theWindow.NeedsLayoutWorkarounds() // Then 
   theWindow.FixTheLayout()
End If

```

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [November 1, 2021, 3:18pm UTC](https://forum.xojo.com/t/if-then/66382/13 "2021-11-01T15:18:13Z")

</div>

Again, it’s all about language design choices. The open curly brace is a direct relation to `Then` with the close curly brace equating to the `End If`, despite the conditions being encapsulated in parens.

At any rate, I’m getting us off-topic. I prefer `Then` be a requirement for readability if nothing else.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [November 1, 2021, 3:24pm UTC](https://forum.xojo.com/t/if-then/66382/14 "2021-11-01T15:24:48Z")

</div>

> [@Rick\_Araujo](#):
>
> I do prefer to write a terse:
> 
> ```auto
> If theWindow.NeedsLayoutWorkarounds() Then theWindow.FixTheLayout()
> 
> ```

I agree with this. I like a good one-line `If`.

---

<div class="post-metadata">

**Author:** ![Alexander\_Slatina](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Alexander\_Slatina](https://forum.xojo.com/u/Alexander_Slatina)\
**Post date:** [November 1, 2021, 3:35pm UTC](https://forum.xojo.com/t/if-then/66382/15 "2021-11-01T15:35:32Z")

</div>

But we both agree that it is absolutely necessary to have a character or coherent characters to indicate the end of a condition. As for example: Then or “)”.

I tried to make that clear.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [November 1, 2021, 3:36pm UTC](https://forum.xojo.com/t/if-then/66382/16 "2021-11-01T15:36:22Z")

</div>

Yes, we can agree on that. Whether it be a close parenthesis, close curly brace, or EOL. There has to be something for the tokenizer to see as the break point in the code block/line.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [November 1, 2021, 4:08pm UTC](https://forum.xojo.com/t/if-then/66382/17 "2021-11-01T16:08:33Z")

</div>

Playing devil’s advocate, why can’t the EOL be that marker?

(And even though I run into the same inconvenience with “Then”, I don’t advocate changing it.)

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [November 1, 2021, 4:09pm UTC](https://forum.xojo.com/t/if-then/66382/18 "2021-11-01T16:09:57Z")

</div>

It could, but you’d still need `Then` (or some other token) for single-line `If`s and why create a confusing difference?

---

<div class="post-metadata">

**Author:** ![Douglas\_Handy](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/d2c977/32.png) [@Douglas\_Handy](https://forum.xojo.com/u/Douglas_Handy)\
**Post date:** [November 1, 2021, 4:12pm UTC](https://forum.xojo.com/t/if-then/66382/19 "2021-11-01T16:12:53Z")

</div>

The great thing about standards is there are so many to choose from!

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [November 1, 2021, 4:17pm UTC](https://forum.xojo.com/t/if-then/66382/20 "2021-11-01T16:17:39Z")

</div>

Making it optional for a traditional IF would not create confusion, IMO, just as the optional keyword after “End” does not create confusion. It would affect backwards compatibility though, but there are already features that do that.

Note that “Then” is already optional for #If, and that, if anything, is confusing, i.e., why is it optional there but required for the traditional If?

(If anything, I would have preferred that the keyword after End be required, but that ship has long sailed.)

[Next page](https://forum.xojo.com/t/if-then/66382.md?page=2)
