Skip to content

Control Flow

Liu Jun edited this page Dec 9, 2019 · 4 revisions

Loop

You still can write for like the one in C++.

for(int i=0; i < 10; ++i)    // implemented
{ 
    //do something...
}
while(true){                 // unimplemented
    // ...
}

And you can use foreach to make it easier. It's not necessary to point out the type explictly.

// unimplemented

for (&val : arr){
    //use the value in the arr to traverse
    //& means using it by reference, otherwise it will be copied 
}
for (it : arr.iterator()){
    //use itertor
}
for (i : arr.index()){
    //use index {0,1,2,...}
}

Branch

if is just the same as the one you know in C++.

// implemented
if(/*any condition*/)
{
    //do something
}

Clone this wiki locally