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

While Loops

while loops are the fastest, most basic loop. Due to the simplicity of this block, most programmers are very familiar with this construct. Parenthesis are optional on these.

The usage is:

while <condition> {
    <code block>
}

As long as the condition is true, the code block will execute. Once, or if, the condition is false, the loop will stop executing and the program will continue.

An example of the use is:

var input
while !( (input = IO.prompt("[Y/n]> ")) in "Yn" ) {
    print "Please enter either 'Y' or 'N'"
}
print "You inputted '#{input}'"

When run, an example execution is:

[Y/n]> No
Please enter either 'Y' or 'N'
[Y/n]> Yes
Please enter either 'Y' or 'N'
[Y/n]> Y
You inputted 'Y'
PreviousFor LoopsNextStandard Library

Last updated 4 years ago

Was this helpful?