Cheddar Documentation
  • Introduction
  • Syntax
  • Literals
    • Comment
    • String
    • Number
    • Array
    • Boolean
  • Mathematics
    • Addition
    • Subtraction
    • Multiplication
    • Division
    • Exponentiation
    • Remainder
    • Negation
    • Sign
    • Root
    • Bitwise AND
    • Bitwise OR
    • Bitwise XOR
    • Bitwise NOT
    • Bitwise Left Shift
    • Bitwise Right Shift
  • Variables
  • Functions
    • Defining
      • Lambda
      • Functionized Operators
      • Functionized Properties
    • Operations
      • Functional Bonding
      • Functional Composition
  • Default Operators
    • What Is
    • Instance-of
    • Actually Is
  • Control Flow
    • Conditional
    • Loops
      • For Loops
      • While Loops
  • Standard Library
    • String
      • Bytes
      • Count
      • Length
      • Match
      • Slice
      • Tail
      • Chars
      • Head
      • Lines
      • Ord
      • Split
      • Test
      • Chunk
      • Index
      • Lower
      • Reverse
      • Substitute
      • Upper
  • Developing
    • Structure
    • Primitive Objects
      • Scope
      • Class
      • Variable
      • Namespace
    • Getting Started
    • API
      • Primitives
        • string
        • number
        • array
        • bool
        • func
        • nil
Powered by GitBook
On this page

Was this helpful?

  1. Control Flow
  2. Loops

For Loops

PreviousLoopsNextWhile Loops

Last updated 4 years ago

Was this helpful?

for loops are the most concise loop construct.

For for loops, parenthesis are required, this is described in the section.

There syntax is highly resemblant of their C counterpart:

for (var i := 0; i < 5; i++) {
    print "i is: #{i}"
}

The syntax of the for loop is:

for (<initalization>; <condition>; <afterthought>) {
    [code block]
}

Essentially the way this works is:

execute initalization
while condition evaluates to true
    execute code block
    execute afterthought

The output of the first for example would be:

i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5

This is because the variable i is initialized to 0 at the beginning. Then, because i is less then 5, it will keep running the code block until i is not less than 5. This happens because the i++ increases i everytime, after, the code block (i.e. the print) is executed.

Control Flow