Login
200-100-while.s2 at [0ab8c75c49]
Login

File s2/unit/200-100-while.s2 artifact 68bda1dd9e part of check-in 0ab8c75c49



var i = 0, max = 1000;
while(i < max){i = i + 1}
assert max===i;

assert 'hi' === while( true ){ break "hi" };

assert undefined === while(false){throw __FLC};

assert 1 === while(true){ scope {catch {break 1} };; };

assert 'CWAL_SCR_SYNTAX' === catch{
       while(/*empty expr is not OK*/){/*empty body is OK*/}
}.codeString();

i = 0;
while(!i){
  var x =0;
  i = while(true){
    if((x=x+1)>3){break x}
    //(x=x+1)>3 && break x
  }; /* semicolon needed b/c of assignment expr */
  true // at EOF, semicolon is optional
}
assert 4===i;

i = 0;
while(!i){
  var x =0;
  i = while(true){
    if((x=x+1)>3){break x}
    //(x=x+1)>3 && break x
  } /* semicolon _normally_ needed b/c of assignment expr,
       but special-casing of keywords ending in blocks
       implicitly treat this EOL as an EOX */
}
assert 4 === i;

i = 0;
assert 4 === while(true){
  ((i = i + 1)<4) && continue;
  break i;
};

i = while(false){};
assert undefined === i;

i = while(true){break};
assert undefined === i;

i = 0;
while(i<3)++i;
assert 3 === i;
assert 3 === i /* make sure the previous line wasn't snarfed by the loop */;

i = 0;
while(i++<3);
assert 4 === i;
assert 4 === i /* make sure the previous line wasn't snarfed by the loop */;