Compare commits
2 Commits
18b79d60d0
...
b71db28075
Author | SHA1 | Date | |
---|---|---|---|
b71db28075 | |||
8072b8a7af |
@ -19,7 +19,7 @@ for #(index, number) in numbers.entries()
|
|||||||
```
|
```
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
val dict = Obj {
|
val dict = .{
|
||||||
apple: 10,
|
apple: 10,
|
||||||
banana: 7,
|
banana: 7,
|
||||||
cherries: 3,
|
cherries: 3,
|
||||||
@ -58,7 +58,7 @@ while index < colors.size()
|
|||||||
|
|
||||||
## Infinite loop
|
## Infinite loop
|
||||||
|
|
||||||
Basically Rust*'s loop.
|
Instead of doing `while true {}` use `loop`.
|
||||||
|
|
||||||
```thp
|
```thp
|
||||||
loop
|
loop
|
||||||
@ -72,8 +72,22 @@ loop
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* Rust is a trademark of the Rust Foundation. THP is not affiliated,
|
|
||||||
endorsed or supported by the Rust Foundation.
|
## Labelled loops
|
||||||
|
|
||||||
|
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,6 +20,8 @@ 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,10 +29,11 @@
|
|||||||
|
|
||||||
<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 class="py-4 pr-2 overflow-x-scroll"
|
<nav id="sidebar" class="py-4 pr-2 overflow-x-scroll"
|
||||||
style="height: calc(100vh - 3rem);"
|
style="height: calc(100vh - 3rem);"
|
||||||
>
|
>
|
||||||
{{pages}}
|
{{pages}}
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -49,6 +50,31 @@
|
|||||||
</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