Multiple conditions can be 'chained' together with else if
:
{#if x > 10}
<p>{x} is greater than 10</p>
{:else if 5 > x}
<p>{x} is less than 5</p>
{:else}
<p>{x} is between 5 and 10</p>
{/if}
App.svelte
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
<script>
let x = 7;
</script>
{#if x > 10}
<p>{x} is greater than 10</p>
{:else}
<p>{x} is between 0 and 10</p>
{/if}
bundling https://unpkg.com/svelte@4.2.19/src/shared/utils/escape.js
999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
›
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
⌄
/* App.svelte generated by Svelte v4.2.19 */
import {
SvelteComponent,
detach,
element,
empty,
init,
insert,
noop,
safe_not_equal
} from "svelte/internal";
import "svelte/internal/disclose-version";
function create_else_block(ctx) {
let p;
return {
c() {
p = element("p");
p.textContent = `${x} is between 0 and 10`;
},
m(target, anchor) {
insert(target, p, anchor);
},
p: noop,
d(detaching) {
if (detaching) {
detach(p);
}
}
};
}
// (5:0) {#if x > 10}
function create_if_block(ctx) {
let p;
return {
c() {
p = element("p");
p.textContent = `${x} is greater than 10`;
},
m(target, anchor) {
insert(target, p, anchor);
},
p: noop,
d(detaching) {
if (detaching) {
detach(p);
}
}
};
}
function create_fragment(ctx) {
let if_block_anchor;
function select_block_type(ctx, dirty) {
if (x > 10) return create_if_block;
return create_else_block;
}
let current_block_type = select_block_type(ctx, -1);
let if_block = current_block_type(ctx);
return {
c() {
if_block.c();
if_block_anchor = empty();
},
m(target, anchor) {
if_block.m(target, anchor);
insert(target, if_block_anchor, anchor);
},
p(ctx, [dirty]) {
if_block.p(ctx, dirty);
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(if_block_anchor);
}
if_block.d(detaching);
}
};
}
let x = 7;
class App extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment, safe_not_equal, {});
}
}
export default App;
result = svelte.compile(source, {
generate:
css:
});9
1
›
/* Add a <style> tag to see compiled CSS */