• Kipper

    v0.12.1
  • Downloads

  • Docs

  • Playground

  • Changelog

  • Kipper

    v0.12.1
    • Downloads

    • Docs

    • Playground

    • Changelog

      • 0.11.0 /
      • Statements /
      • If Statement
    Kipper Docs
    • next
    • latest
    • 0.11.0
    • 0.10.4
    • 0.9.2
    • Overview

    • Quickstart

    • Goals for Kipper

    • Supported platforms

    • Usage Examples

      • Overview

      • Compiler Setup

        • Overview

          • index

          • compiler

          • errors

          • logger

          • utils

          • config

          • index

          • index

        • Overview

        • new

        • run

        • compile

        • help

        • version

    • Variables

      • Overview

      • String Type

      • Number Type

      • Boolean Type

      • Void Type

      • Null Type

      • Undefined Type

      • Array Type

      • Overview

      • Arithmetic Expression

      • Assignment Expression

      • Conditional Expressions

      • Logical Expressions

      • Bitwise Expression

      • Relational Expressions

      • Convert Expression

      • F-String Expression

      • Member Access Expression

      • Function Call Expression

      • Overview

      • Expression Statement

      • If Statement

      • While Loop

      • Do-While Loop

      • For Loop

      • Compound Statement

      • Jump Statement

    • Functions

    • Comments

    • Built-in Functions

      • 0.11.0 /
      • Statements /
      • If Statement
    • 0.11.0 /
    • Statements /
    • If Statement

    Edit page

    If Statement

    If-statements or also if-else-statements make up an essential part of every program. These statements check if a specified condition is met and react accordingly. If the specified condition isn’t met, the program will execute a different code, which may be specified inside an else code block.

    It is also possible to check multiple different conditions by using else if blocks.

    Syntax

    They must have a single starting if, may have multiple extending else if branches and can have a single ending else branch, which is evaluated if the previous condition were all false.

    if (CONDITION) STATEMENT;
    // Required
    else if (CONDITION) STATEMENT;
    // Optional - No limit for the amount of 'else if' branches
    else STATEMENT; // Optional

    Examples

    // Simple comparison of a value
    var var1: num = 4;
    if (var1 == 4) {
      call print("It's 4");
    } else {
      call print("It's not 4");
    }
    
    // Simple else-if branch chaining
    var var2: num = 5;
    if (var2 < 5) {
      call print("It's less than 5");
    } else if (var2 == 5) {
      call print("It's 5");
    } else {
      call print("It's more than 5");
    }
    
    // Simple else-if branch chaining without braces
    var var3: num = 123;
    if (var3 < 123)
      call print("It's less than 123");
    else if (var3 == 123) {
      call print("It's 123");
    else
      call print("It's more than 123");
    
    // Nested if-statement
    var var4: str = "Hello!";
    if (var4 == "Hello")
      call print("It says Hello. Hello back :)");
    else
      if (var4 == "Hello!")
        call print("It says Hello! Hello back!");
      else
        call print(f"It says: {var4}");
  • Developed at and supported by:

    • Releases
    • GitHub
    • Security
    • Issue Tracker
    • License
  • Copyright © 2021-2025 Luna Klatzer, Lorenz Holzbauer & Fabian Baitura.
    Kipper is licensed under the GPL-3.0-or-later license.