# Case statement (expr.)

**URL:** https://discourse.nixos.org/t/case-statement-expr/27741
**Category:** Help
**Created:** [April 30, 2023, 11:02am UTC](https://discourse.nixos.org/t/case-statement-expr/27741 "2023-04-30T11:02:07Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![qwqawawow](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qwqawawow/32/9603_2.png) [@qwqawawow](https://discourse.nixos.org/u/qwqawawow)
#### Post date: [February 16, 2024, 5:28pm UTC](https://discourse.nixos.org/t/case-statement-expr/27741/12 "2024-02-16T17:28:56Z")

</div>

Someone emulated this  
[nixpkgs/pkgs/build-support/coq/extra-lib.nix at master · NixOS/nixpkgs (github.com)](https://github.com/NixOS/nixpkgs/blob/5185539c51ba658e70b29e01c0c320a85f4e2098/pkgs/build-support/coq/extra-lib.nix#L98)

````auto
  /* Emulate a "switch - case" construct,
   instead of relying on `if then else if ...` */
  /* Usage:
  ```nix
  switch-if [
    if-clause-1
    ..
    if-clause-k
  ] default-out

````

where a if-clause has the form `{ cond = b; out = r; }`  
the first branch such as `b` is true \*/

```auto

```

---

_[View the full topic](https://discourse.nixos.org/t/case-statement-expr/27741)._
