HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to GoVariablesData TypesOperatorsStringsArray & SliceMap (Dictionary)Conditions (if / switch)Loops (for)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array & Slice
🗂️ Map
🔁 Condition & Loop
if / elseswitchfor (three forms)for ... range
🧩 Function
Go›REFERENCE›Condition & Loop›if / else

if / else

Executes code based on a condition.

Syntax

if condition { } else { }

Description

Condition WITHOUT PARENTHESES, blocks with curly braces. Intermediate conditions are added with else if.

Example

Loading editor…

Expected output

Passed

When to use?

Flow branching.

Common mistakes

  • ⚠️ Do NOT put the condition in parentheses; { } are mandatory.

Related commands

switchfor (three forms)
switch →
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code