Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
23
Task/Loops-Nested/Ballerina/loops-nested.ballerina
Normal file
23
Task/Loops-Nested/Ballerina/loops-nested.ballerina
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import ballerina/io;
|
||||
import ballerina/random;
|
||||
|
||||
public function main() returns error? {
|
||||
int[20][20] a = [];
|
||||
foreach int i in 0...19 {
|
||||
foreach int j in 0...19 {
|
||||
a[i][j] = check random:createIntInRange(1, 21);
|
||||
}
|
||||
}
|
||||
boolean found = false;
|
||||
foreach int i in 0...19 {
|
||||
foreach int j in 0...19 {
|
||||
io:print(a[i][j].toString().padStart(3));
|
||||
if a[i][j] == 20 {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
io:println();
|
||||
if found { break; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,14 @@ procedure main()
|
|||
|
||||
every !(!(L := list(10)) := list(10)) := ?20 # setup a 2d array of random numbers up to 20
|
||||
|
||||
every i := 1 to *L do # using nested loops
|
||||
every j := 1 to *L[i] do
|
||||
if L[i,j] = 20 then
|
||||
break break write("L[",i,",",j,"]=20")
|
||||
|
||||
every i := 1 to *L do{ # using nested loops
|
||||
every j := 1 to *L[i] do{
|
||||
writes(" ",L[i,j])
|
||||
if L[i,j] = 20 then{
|
||||
write()
|
||||
break break
|
||||
}
|
||||
}
|
||||
write()
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
every x := L[i := 1 to *L,1 to *L[i]] do
|
||||
if x = 20 then break write("L[",i,",",j,"]=20") # more succinctly
|
||||
|
||||
every if !!L = 20 then break write("Found !!L=20") # even more so (but looses the values of i and j
|
||||
e := !!L & write(e) & e = 20
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue