• Kipper

    v0.12.1
  • Downloads

  • Docs

  • Playground

  • Changelog

  • Kipper

    v0.12.1
    • Downloads

    • Docs

    • Playground

    • Changelog

      • 0.11.0 /
      • Statements /
      • For Loop
    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 /
      • For Loop
    • 0.11.0 /
    • Statements /
    • For Loop

    Edit page

    For Loop

    For-loops are statements with a loop-expression, a loop condition and a statement body that are executed as long as a specified condition is met.

    For-loops have the unique attribute, unlike while-loops and do-while-loops, of having an executable loop expression, which is evaluated at the end of every loop cycle. This loop expression can be used to do repeating tasks at the end of a loop cycle, like calling a function or increasing a counter.

    Syntax

    for (INIT_EXPRESSION (OPTIONAL); CONDITION (OPTIONAL); LOOP_EXPRESSIONS (OPTIONAL)...) STATEMENT;

    Execution Schema

    • Evaluate INIT_EXPRESSION, if it exists (Only the first time).
    • Check CONDITION, if it exists, before running the STATEMENT. If CONDITION is false, then the loop will be stopped!
    • Run STATEMENT if CONDITION was true.
    • If the loop was not stopped using return or break, evaluate LOOP_EXPRESSION after finishing the execution of STATEMENT.

    Examples

    // ✓ Simple for-loop with an execution counter
    for (var i: num = 1; i < 10; i++) {
      call print(f"Running for the {i}. time!");
    }
    
    // ✓ Simple for-loop with two execution counters
    var j: num = 0;
    for (var i: num = 1; i < 10; i++, j++) {
      call print(f"i = {i}");
    }
    call print(f"Additional variable j = {j}"); // -> Additional variable j = 10
    
    // X Infinite loop - Avoid this, as it results in your program freezing/running forever
    for ( ; ; ) {
      call print(f"Running for the {i}. time!");
    }
  • Developed at:

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