Skip to content

Latest commit

 

History

History
66 lines (56 loc) · 1.34 KB

statement.md

File metadata and controls

66 lines (56 loc) · 1.34 KB

SEL Statements

Statement types

block statement

{
  x = 10; 
  x += 10; 
}

expression statement

x = 10; 

if statement

  • if (condition) ... else if (condition) ... else ...
  • condition is an expression with boolean result
  • the statement can be a multi-statement block or a single statement
  • else part is optional
if (2 > 1) x = 10; else x = -10;
int x=10; if(x>0) x+=10; else x-=10; return x;

while statement

  • while(condition) ...
  • condition is an expression with a boolean result
  • the statement can be a multi-statement block or a single statement
int x = 0; while(x<10) x+=3; return x;

for statement

  • for(initialization, condition, update) ...
  • if cond is missing, it is always true.
for(;;) {} is an infinite loop 
for(x=0; x<10; x+=1) x+=1; return x;

break statement

  • break will exit the for/while loop
for(x=0; x<10; x+=1) break; return x;

continue statement

  • continue will skip the remaining statements in the same iteration
for(x=0; x<10; x+=1) {x+=10; continue; x+=10;} return x;

return statement

  • return the result of the whole expression.
for(x=0; x<10; x+=1) {x+=10; return x; x+=10;}

throw statement

  • throw an error in a string representation and return it.
throw "invalid variable value: " + x;