Skip to content

while ... do: inconsistent handling of whitespace / indentation #18754

@mathias-brandewinder

Description

@mathias-brandewinder

while ... do expressions handle whitespace / indentation in a manner that is not consistent with if ... then ... else expressions.
This is problematic when the test expression is lengthy and would be more clearly written using multiple lines, along the lines of:

while
    x > 10
    &&
    x < 20
do ...   

Repro steps

Provide the steps required to reproduce the problem:

let mutable x = 0
while
    x < 10
do
    x <- x + 1

Expected behavior

I would expect this to be valid syntax, in a fashion similar to

if
    x < 10
then
    // do something
else
    // do something

Actual behavior

error FS0010: Incomplete structured construct at or before this point in expression
Missing 'do' in 'while' expression. Expected 'while <expr> do <expr>'.

Known workarounds

Any indentation of do resolves the issue:

let mutable x = 0
while 
    x < 10
 do
    x <- x + 1

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions