June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -2,5 +2,23 @@ Start with a value at 0. Loop while value mod 6 is not equal to 0.
Each time through the loop, add 1 to the value then print it.
The loop must execute at least once.
;Related tasks:
*   [[Loop over multiple arrays simultaneously]]
*   [[Loops/Break]]
*   [[Loops/Continue]]
*   [[Loops/Do-while]]
*   [[Loops/Downward for]]
*   [[Loops/For]]
*   [[Loops/For with a specified step]]
*   [[Loops/Foreach]]
*   [[Loops/Increment loop index within loop body]]
*   [[Loops/Infinite]]
*   [[Loops/N plus one half]]
*   [[Loops/Nested]]
*   [[Loops/While]]
;Reference:
* [[wp:Do while loop|Do while loop]] Wikipedia.
<br><br>

View file

@ -0,0 +1,15 @@
component loops_do_while
export Executable
var x:ZZ32 = 0
run() = label loop
while true do
x += 1
println(x)
if (x MOD 6) = 0
then exit loop
end
end
end loop
end

View file

@ -0,0 +1,8 @@
10 LET I% = 0
20 ' first iteration - before the WHILE
30 PRINT I%
40 LET I% = I% + 1
50 WHILE I% MOD 6 <> 0
60 PRINT I%
70 LET I% = I% + 1
80 WEND

View file

@ -0,0 +1,4 @@
10 LET I% = 0
20 PRINT I%
30 LET I% = I% + 1
40 IF I% MOD 6 <> 0 THEN GOTO 20

View file

@ -0,0 +1,10 @@
import Data.IORef
import Control.Monad.Loops
main = do
x <- newIORef 0;
iterateWhile (\val -> val `mod` 6 /= 0 ) $ do
modifyIORef x (+1)
val <- readIORef x
print val
return val

View file

@ -0,0 +1,20 @@
// generator with the do while loop
function* getValue(stop) {
var i = 0;
do {
yield ++i;
} while (i % stop != 0);
}
// function to print the value and invoke next
function printVal(g, v) {
if (!v.done) {
console.log(v.value);
setImmediate(printVal, g, g.next());
}
}
(() => {
var gen = getValue(6);
printVal(gen, gen.next());
})();

View file

@ -0,0 +1,6 @@
1
2
3
4
5
6

View file

@ -1,4 +1,4 @@
template doWhile(a: expr, b: stmt): stmt =
template doWhile(a, b: untyped): untyped =
b
while a:
b

View file

@ -0,0 +1,7 @@
Red []
i: 0
until [
?? i
i: i + 1
i % 6 = 0 ;; loop , until this is true...
]