import ballerina/io;function main (string[] args) { int i = 0;
while (i < 3) {
io:println(i);
i = i + 1;
} int j = 0;
while (j < 5) {
io:println(j);
j = j + 1;
if (j == 3) {
break;
}
} int k = 0;
while (k < 5) {
if (k < 3) {
k = k + 1;
next;
} io:println(k);
k = k + 1;
}
}
WhileBallerina has only one looping construct. Here is an example usage of while. |
|
import ballerina/io;
|
|
function main (string[] args) {
|
|
int i = 0;
|
|
while (i < 3) {
io:println(i);
i = i + 1;
}
|
This is a basic while loop. |
int j = 0;
while (j < 5) {
io:println(j);
j = j + 1;
|
|
if (j == 3) {
break;
}
}
|
Use the break statement if you want to break the loop. |
int k = 0;
while (k < 5) {
|
|
if (k < 3) {
k = k + 1;
next;
}
|
Sample usage of the next statement. |
io:println(k);
k = k + 1;
}
}
|
|
$ ballerina run while.bal
0
1
2
0
1
2
3
4
|
|