mardi 11 février 2020

Do you need a multiple Else statements if you run multiple one line If statements?

I have a statement that does two If checks on one line:

If JMdict(i).Senses.Count > 0 Then If JMdict(i).Senses.First.Gloss.Count > 0 Then meaning = JMdict(i).Senses.First.Gloss.First Else meaning = ""

I'm wondering if I need to add a second Else, as in below:

If JMdict(i).Senses.Count > 0 Then If JMdict(i).Senses.First.Gloss.Count > 0 Then meaning = JMdict(i).Senses.First.Gloss.First Else meaning = "" Else meaning = ""

Or will the first Else cover all code paths?

Basically, should I be doing

If [First Condition] Then If [Second Condition] Then [Result] Else [Nothing happens]

Or

If [First Condition] Then If [Second Condition] Then [Result] Else [Nothing happens] Else [Nothing happens]

I'm aware I could use AndAlso as a neater solution, I'm just curious how this one-line nested If would work in practice.

Aucun commentaire:

Enregistrer un commentaire