A
A
Andrey Privalov2018-11-15 16:07:02
code review
Andrey Privalov, 2018-11-15 16:07:02

Is there any reason to use the first or second option?

Below are two options.
We have opinions in favor of using the first (I) option.
And there are supporters of the second option (they will follow this issue).
Arguments and mine and opponents were different. We came to the conclusion that it would be nice to ask for the opinions of the community.
Thank you)

// #1
for {
  if a1 !== b1 {
    // .. some code 1
    continue
  }
  if a2 !== b2 {
    // .. some code 2
    continue
  }
  // .. some code 3
}

// #2
for {
  if a1 !== b2 {
    // .. some code 1 
  } else if a2 !== b2 {
    // .. some code 2
  } else {
    // .. some code 3
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2018-11-15
@xmoonlight

#1 - else if - required!
Further - the integrity and readability: it does not affect the speed.

A
Artemy, 2018-11-15
@MetaAbstract

If the control flow of the code is an invariant, then it doesn't matter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question