Go

If With Initialiser in Go

GoControl FlowIf Statementbeginner

An if can declare a variable before its condition. That variable is scoped to the if and its else, keeping it out of the surrounding function.

expected output

long 6

Why practise typing this

Typing control flow code builds muscle memory for the symbols and indentation Go uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More Go practice

Browse all Go snippets →