# Switch Question (sorry so simple)

**URL:** <https://forum.golangbridge.org/t/switch-question-sorry-so-simple/36917>\
**Category:** Getting Help\
**Created:** [November 18, 2024, 9:57pm UTC](https://forum.golangbridge.org/t/switch-question-sorry-so-simple/36917 "2024-11-18T21:57:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Press](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/dan_press/32/15705_2.png) [@Dan\_Press](https://forum.golangbridge.org/u/Dan_Press)\
**Post date:** [November 18, 2024, 9:57pm UTC](https://forum.golangbridge.org/t/switch-question-sorry-so-simple/36917/1 "2024-11-18T21:57:52Z")

</div>

My question is why does this work:

```
switch {
    case cfg.PlayNew.TreeReportingOptions.Type == "very narrow":
        treeMoveWidth = 1
    case cfg.PlayNew.TreeReportingOptions.Type == "narrow":
        treeMoveWidth = 3
    case cfg.PlayNew.TreeReportingOptions.Type == "regular":
        treeMoveWidth = 8

    }

```

BUT this does not??? Note: cfg.PlayNew.TreeReportingOptions.Type is a string

```
switch cfg.PlayNew.TreeReportingOptions.Type {
    case "very narrow":
        treeMoveWidth = 1
    case "narrow":
        treeMoveWidth = 3
    case "regular":
        treeMoveWidth = 8

    }

```

Thank you for your time!

---

<div class="post-metadata">

**Author:** ![Dean\_Davidson](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/dean_davidson/32/9685_2.png) [@Dean\_Davidson](https://forum.golangbridge.org/u/Dean_Davidson)\
**Post date:** [November 18, 2024, 10:09pm UTC](https://forum.golangbridge.org/t/switch-question-sorry-so-simple/36917/2 "2024-11-18T22:09:13Z")

</div>

The second example should be working fine. This:

```go
func main() {
	treeMoveWidth := 0
	treeReportingOptionsType := "narrow"
	switch treeReportingOptionsType {
	case "very narrow":
		treeMoveWidth = 1
	case "narrow":
		treeMoveWidth = 3
	case "regular":
		treeMoveWidth = 8
	}
	fmt.Println("treeMoveWidth =", treeMoveWidth)
}

```

… prints the following:

```auto
treeMoveWidth = 3

```

You can [run it yourself on the playground](https://go.dev/play/p/gg1UuCoNXfn).

---

<div class="post-metadata">

**Author:** ![Dan\_Press](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/dan_press/32/15705_2.png) [@Dan\_Press](https://forum.golangbridge.org/u/Dan_Press)\
**Post date:** [November 19, 2024, 6:55pm UTC](https://forum.golangbridge.org/t/switch-question-sorry-so-simple/36917/3 "2024-11-19T18:55:28Z")

</div>

Thanks turned out there was an unprintable character in the code so that is why it would not compile.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [February 17, 2025, 6:56pm UTC](https://forum.golangbridge.org/t/switch-question-sorry-so-simple/36917/4 "2025-02-17T18:56:16Z")

</div>

Closed on February 17, 2025, 6:56pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
