4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

If Statement vs. Switch Statement

If Statement vs. Switch Statement

If Statement

![ifstatement.png](https://steemitimages.com/DQmWtdqDqpRuHEqn5nfMBTnHkMdsqRrxZB9KSVeFPyFr33a/ifstatement.png)

Switch Statement

![switch.png](https://steemitimages.com/DQmYKsGbhojU4BSDk8rZrJiriiwbAm3UWrZdgHmojYdLzvR/switch.png)

In my experience switch statement is faster than if statement. It always depends on the situation whether you will use if statement or switch statement. I use switch statement when I am trying to switch the value of a single variable. However switch statement is not always faster than the if statement as some of the compilers are able to optimize performance by constructing jump tables. In this way each condition doesn't have to be tested in if/else statements.

1 upvotes $0.00

Replies (0)

Conversation

No replies yet

Replies will appear here as people join the conversation.

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: