Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

switch-statement

Using break statement in switch

December 12, 2023 by Tarik

The break statement inside a switch can be used when you don’t need a case to have any actual functionality, but want to include it to make your logic easier or clearer. Suppose for example you want to use a switch statement to determine if a given year is a leap year or not. (This … Read more

Categories switch-statement Tags break, swift, switch-statement Leave a comment

Why isn’t fallthrough allowed in a type switch?

September 12, 2023 by Tarik

How would you expect fallthrough to work? In this type switch, the i variable has a type that depends on the particular case that’s invoked. So in the case bool the i variable is typed as bool. But in case string it’s typed as string. So either you’re asking for i to magically morph its … Read more

Categories switch-statement Tags go, switch-statement Leave a comment

What is the difference between Cond and Case?

August 11, 2023 by Tarik

Let me put if to the club too. You use if with one condition and a possible else, that’s it. You use the cond statement when you have more than one condition and an if statement isn’t enough, by the end, the case statement is used when you want to pattern match some data. Let’s … Read more

Categories switch-statement Tags elixir, switch-statement Leave a comment

Elm Compiler running forever, computer just getting hot

January 8, 2023 by Tarik

Large case expressions will cause the optimizer to take a long time, as of 0.16. Here’s the discussion on Elm-Discuss bringing up the issue, and a gist of the nasty case match.

Categories switch-statement Tags elm, pattern-matching, switch-statement Leave a comment

When to use If-else if-else over switch statements and vice versa [duplicate]

January 1, 2023 by Tarik

As with most things you should pick which to use based on the context and what is conceptually the correct way to go. A switch is really saying “pick one of these based on this variables value” but an if statement is just a series of boolean checks. As an example, if you were doing: … Read more

Categories switch-statement Tags switch-statement Leave a comment

swift case falling through

November 19, 2022 by Tarik

Yes. You can do so as follows: var testVal = “hello” var result = 0 switch testVal { case “one”, “two”: result = 1 default: result = 3 } Alternatively, you can use the fallthrough keyword: var testVal = “hello” var result = 0 switch testVal { case “one”: fallthrough case “two”: result = 1 … Read more

Categories switch-statement Tags swift, switch-statement Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa