Compare commits
No commits in common. "b71db280756780f6fa14569c8ddbd77b21ed0e72" and "18b79d60d054312ce1db4a39afcf6b0026c42671" have entirely different histories.
b71db28075
...
18b79d60d0
0
md/learn/flow-control/break-continue.md
Normal file
0
md/learn/flow-control/break-continue.md
Normal file
@ -19,7 +19,7 @@ for #(index, number) in numbers.entries()
|
|||||||
```
|
```
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
val dict = .{
|
val dict = Obj {
|
||||||
apple: 10,
|
apple: 10,
|
||||||
banana: 7,
|
banana: 7,
|
||||||
cherries: 3,
|
cherries: 3,
|
||||||
@ -58,7 +58,7 @@ while index < colors.size()
|
|||||||
|
|
||||||
## Infinite loop
|
## Infinite loop
|
||||||
|
|
||||||
Instead of doing `while true {}` use `loop`.
|
Basically Rust*'s loop.
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
loop
|
loop
|
||||||
@ -72,22 +72,8 @@ loop
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Rust is a trademark of the Rust Foundation. THP is not affiliated,
|
||||||
## Labelled loops
|
endorsed or supported by the Rust Foundation.
|
||||||
|
|
||||||
You can give labels to loops, allowing you to `break` and `continue` in nested loops.
|
|
||||||
|
|
||||||
```thp
|
|
||||||
:top for i in values_1
|
|
||||||
{
|
|
||||||
for j in values_2
|
|
||||||
{
|
|
||||||
// ...
|
|
||||||
break :top
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,8 +20,6 @@ children:
|
|||||||
- name: Flow control
|
- name: Flow control
|
||||||
path: flow-control
|
path: flow-control
|
||||||
children:
|
children:
|
||||||
- name: Blocks
|
|
||||||
path: blocks
|
|
||||||
- name: Conditionals
|
- name: Conditionals
|
||||||
path: conditionals
|
path: conditionals
|
||||||
- name: Loops
|
- name: Loops
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<a class="inline-block font-display text-lg rounded-full border-2 border-pink-400 py-2 px-8
|
<a class="inline-block font-display text-lg rounded-full border-2 border-pink-400 py-2 px-8
|
||||||
transition-colors hover:text-black hover:bg-pink-400" href="/learn/">
|
transition-colors hover:text-black hover:bg-pink-400" href="/learn">
|
||||||
Tutorial
|
Tutorial
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@ -29,11 +29,10 @@
|
|||||||
|
|
||||||
<div class="grid grid-cols-[14rem_auto_12rem] container mx-auto">
|
<div class="grid grid-cols-[14rem_auto_12rem] container mx-auto">
|
||||||
<div class="pt-12 h-screen sticky top-0">
|
<div class="pt-12 h-screen sticky top-0">
|
||||||
<nav id="sidebar" class="py-4 pr-2 overflow-x-scroll"
|
<nav class="py-4 pr-2 overflow-x-scroll"
|
||||||
style="height: calc(100vh - 3rem);"
|
style="height: calc(100vh - 3rem);"
|
||||||
>
|
>
|
||||||
{{pages}}
|
{{pages}}
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -50,31 +49,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
|
||||||
let current_uri = window.location.pathname;
|
|
||||||
if (!current_uri.endsWith("/") && !current_uri.endsWith(".html")) {
|
|
||||||
current_uri += ".html";
|
|
||||||
}
|
|
||||||
|
|
||||||
const sidebar = document.getElementById("sidebar");
|
|
||||||
const links = sidebar.querySelectorAll("a");
|
|
||||||
for (const link of [...links]) {
|
|
||||||
if (link.getAttribute("href") === current_uri) {
|
|
||||||
console.log(sidebar.offsetTop);
|
|
||||||
console.log(link.offsetTop);
|
|
||||||
|
|
||||||
const viewport_middle = window.innerHeight / 2;
|
|
||||||
|
|
||||||
sidebar.scrollTop = link.offsetTop - sidebar.offsetTop - 250;
|
|
||||||
|
|
||||||
link.classList.add("bg-pink-200", "dark:bg-pink-950");
|
|
||||||
// link.scrollIntoView({ behavior: "instant", block: "nearest", inline: "nearest" });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<script src="/js/highlighter.js"></script>
|
<script src="/js/highlighter.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// Add an editor to all code samples
|
// Add an editor to all code samples
|
||||||
|
Loading…
Reference in New Issue
Block a user