-
Notifications
You must be signed in to change notification settings - Fork 6
/
statements-&-expressions.html
983 lines (937 loc) · 52.1 KB
/
statements-&-expressions.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" href="assets/styles/style.css">
<link rel="stylesheet" href="assets/styles/vlang-playground.css">
<title>V Documentation</title>
<style>
.subtopic {
margin-left: 20px !important;
}
</style>
</head>
<body>
<header>
<div class="header-container">
<ul class="header-container-left-section">
<li class="aside-topics-open">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 -960 960 960">
<path d="M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z" fill="white" />
</svg>
</li>
</ul>
<div class="logo"></div>
<ul class="header-container-right-section">
<li>
<a href="https://github.com/vlang/docs/tree/generator" target="_blank">Source code</a>
</li>
<li class="js-change-theme__action change-theme">
<svg class="theme-icon sun" width="30" height="30" viewBox="0 0 30 30" fill="none"
xmlns="http://www.w3.org/2000/svg">
<!-- <g clip-path="url(#clip0_4_47)"> -->
<path
d="M14.9854 1.92059C14.7382 1.92445 14.5026 2.02624 14.3304 2.20361C14.1581 2.38099 14.0633 2.61946 14.0667 2.86668V5.66668C14.0649 5.79036 14.0878 5.91315 14.1339 6.02792C14.18 6.14269 14.2485 6.24715 14.3353 6.33523C14.4222 6.42331 14.5256 6.49325 14.6398 6.54098C14.7539 6.58872 14.8763 6.61331 15 6.61331C15.1237 6.61331 15.2462 6.58872 15.3603 6.54098C15.4744 6.49325 15.5778 6.42331 15.6647 6.33523C15.7515 6.24715 15.82 6.14269 15.8661 6.02792C15.9122 5.91315 15.9351 5.79036 15.9333 5.66668V2.86668C15.935 2.74181 15.9117 2.61786 15.8646 2.50219C15.8176 2.38651 15.7478 2.28145 15.6594 2.19323C15.571 2.10501 15.4658 2.03542 15.35 1.98859C15.2343 1.94176 15.1103 1.91863 14.9854 1.92059ZM6.41042 5.47892C6.2249 5.47933 6.04372 5.53501 5.88999 5.63885C5.73626 5.7427 5.61696 5.89 5.54732 6.06195C5.47768 6.2339 5.46086 6.4227 5.499 6.60425C5.53714 6.7858 5.62852 6.95187 5.76146 7.08126L7.74115 9.06095C7.82715 9.15052 7.93016 9.22204 8.04415 9.2713C8.15814 9.32056 8.28081 9.34659 8.40498 9.34785C8.52915 9.34912 8.65232 9.32559 8.76728 9.27865C8.88225 9.23172 8.98669 9.16231 9.0745 9.07451C9.1623 8.9867 9.23171 8.88226 9.27864 8.76729C9.32558 8.65233 9.34911 8.52915 9.34784 8.40498C9.34658 8.28081 9.32056 8.15814 9.27129 8.04416C9.22203 7.93017 9.15051 7.82716 9.06094 7.74116L7.08125 5.76147C6.99406 5.67184 6.88975 5.60065 6.77451 5.55211C6.65928 5.50357 6.53546 5.47868 6.41042 5.47892V5.47892ZM23.5604 5.47892C23.3179 5.48614 23.0878 5.58748 22.9188 5.76147L20.9391 7.74116C20.8495 7.82716 20.778 7.93017 20.7287 8.04416C20.6795 8.15814 20.6534 8.28081 20.6522 8.40498C20.6509 8.52915 20.6744 8.65233 20.7214 8.76729C20.7683 8.88225 20.8377 8.9867 20.9255 9.0745C21.0133 9.16231 21.1178 9.23171 21.2327 9.27865C21.3477 9.32558 21.4709 9.34911 21.595 9.34785C21.7192 9.34659 21.8419 9.32056 21.9559 9.2713C22.0698 9.22203 22.1729 9.15052 22.2589 9.06095L24.2385 7.08126C24.3734 6.95016 24.4655 6.78138 24.5028 6.59703C24.5401 6.41268 24.5209 6.22136 24.4476 6.04814C24.3742 5.87493 24.2503 5.7279 24.092 5.62633C23.9337 5.52475 23.7484 5.47337 23.5604 5.47892ZM15 8.46668C13.2673 8.46668 11.6055 9.15501 10.3802 10.3802C9.155 11.6055 8.46667 13.2673 8.46667 15C8.46667 16.7328 9.155 18.3945 10.3802 19.6198C11.6055 20.845 13.2673 21.5333 15 21.5333C16.7328 21.5333 18.3945 20.845 19.6198 19.6198C20.845 18.3945 21.5333 16.7328 21.5333 15C21.5333 13.2673 20.845 11.6055 19.6198 10.3802C18.3945 9.15501 16.7328 8.46668 15 8.46668V8.46668ZM2.86667 14.0667C2.74299 14.0649 2.6202 14.0878 2.50543 14.1339C2.39066 14.18 2.2862 14.2485 2.19812 14.3353C2.11004 14.4222 2.0401 14.5257 1.99237 14.6398C1.94463 14.7539 1.92004 14.8763 1.92004 15C1.92004 15.1237 1.94463 15.2462 1.99237 15.3603C2.0401 15.4744 2.11004 15.5779 2.19812 15.6647C2.2862 15.7515 2.39066 15.82 2.50543 15.8661C2.6202 15.9122 2.74299 15.9351 2.86667 15.9333H5.66667C5.79035 15.9351 5.91314 15.9122 6.02791 15.8661C6.14268 15.82 6.24714 15.7515 6.33522 15.6647C6.4233 15.5779 6.49324 15.4744 6.54098 15.3603C6.58871 15.2462 6.6133 15.1237 6.6133 15C6.6133 14.8763 6.58871 14.7539 6.54098 14.6398C6.49324 14.5257 6.4233 14.4222 6.33522 14.3353C6.24714 14.2485 6.14268 14.18 6.02791 14.1339C5.91314 14.0878 5.79035 14.0649 5.66667 14.0667H2.86667ZM24.3333 14.0667C24.2097 14.0649 24.0869 14.0878 23.9721 14.1339C23.8573 14.18 23.7529 14.2485 23.6648 14.3353C23.5767 14.4222 23.5068 14.5257 23.459 14.6398C23.4113 14.7539 23.3867 14.8763 23.3867 15C23.3867 15.1237 23.4113 15.2462 23.459 15.3603C23.5068 15.4744 23.5767 15.5779 23.6648 15.6647C23.7529 15.7515 23.8573 15.82 23.9721 15.8661C24.0869 15.9122 24.2097 15.9351 24.3333 15.9333H27.1333C27.257 15.9351 27.3798 15.9122 27.4946 15.8661C27.6093 15.82 27.7138 15.7515 27.8019 15.6647C27.89 15.5779 27.9599 15.4744 28.0076 15.3603C28.0554 15.2462 28.08 15.1237 28.08 15C28.08 14.8763 28.0554 14.7539 28.0076 14.6398C27.9599 14.5257 27.89 14.4222 27.8019 14.3353C27.7138 14.2485 27.6093 14.18 27.4946 14.1339C27.3798 14.0878 27.257 14.0649 27.1333 14.0667H24.3333ZM8.38282 20.6565C8.14034 20.6637 7.9102 20.7651 7.74115 20.9391L5.76146 22.9188C5.67189 23.0048 5.60038 23.1078 5.55111 23.2218C5.50185 23.3357 5.47582 23.4584 5.47456 23.5826C5.4733 23.7068 5.49683 23.8299 5.54376 23.9449C5.5907 24.0599 5.6601 24.1643 5.74791 24.2521C5.83572 24.3399 5.94016 24.4093 6.05512 24.4563C6.17009 24.5032 6.29326 24.5267 6.41743 24.5255C6.5416 24.5242 6.66427 24.4982 6.77825 24.4489C6.89224 24.3996 6.99525 24.3281 7.08125 24.2386L9.06094 22.2589C9.19581 22.1278 9.28793 21.959 9.32522 21.7746C9.36252 21.5903 9.34325 21.399 9.26995 21.2257C9.19664 21.0525 9.07272 20.9055 8.91442 20.8039C8.75612 20.7024 8.57082 20.651 8.38282 20.6565ZM21.5898 20.6565C21.4042 20.6566 21.2227 20.712 21.0687 20.8157C20.9147 20.9194 20.7951 21.0667 20.7253 21.2387C20.6554 21.4107 20.6384 21.5997 20.6765 21.7814C20.7146 21.9631 20.806 22.1294 20.9391 22.2589L22.9188 24.2386C23.0048 24.3281 23.1078 24.3996 23.2218 24.4489C23.3357 24.4982 23.4584 24.5242 23.5826 24.5254C23.7067 24.5267 23.8299 24.5032 23.9449 24.4562C24.0598 24.4093 24.1643 24.3399 24.2521 24.2521C24.3399 24.1643 24.4093 24.0599 24.4562 23.9449C24.5032 23.8299 24.5267 23.7068 24.5254 23.5826C24.5242 23.4584 24.4982 23.3357 24.4489 23.2218C24.3996 23.1078 24.3281 23.0048 24.2385 22.9188L22.2589 20.9391C22.1719 20.8497 22.0679 20.7786 21.953 20.7301C21.8381 20.6815 21.7146 20.6565 21.5898 20.6565V20.6565ZM14.9854 23.3873C14.7382 23.3911 14.5026 23.4929 14.3304 23.6703C14.1581 23.8477 14.0633 24.0861 14.0667 24.3333V27.1333C14.0649 27.257 14.0878 27.3798 14.1339 27.4946C14.18 27.6094 14.2485 27.7138 14.3353 27.8019C14.4222 27.89 14.5256 27.9599 14.6398 28.0077C14.7539 28.0554 14.8763 28.08 15 28.08C15.1237 28.08 15.2462 28.0554 15.3603 28.0077C15.4744 27.9599 15.5778 27.89 15.6647 27.8019C15.7515 27.7138 15.82 27.6094 15.8661 27.4946C15.9122 27.3798 15.9351 27.257 15.9333 27.1333V24.3333C15.935 24.2085 15.9117 24.0845 15.8646 23.9689C15.8176 23.8532 15.7478 23.7481 15.6594 23.6599C15.571 23.5717 15.4658 23.5021 15.35 23.4553C15.2343 23.4084 15.1103 23.3853 14.9854 23.3873V23.3873Z"
fill="white" />
<!-- </g> -->
<defs>
<clipPath id="clip0_4_47">
<rect width="24" height="24" fill="white" transform="translate(1 1)" />
</clipPath>
</defs>
</svg>
<svg class="theme-icon moon" width="30" height="30" viewBox="0 0 30 30" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M27.1371 20.5912C25.7519 21.0833 24.2605 21.3512 22.7065 21.3512C15.3985 21.3512 9.47424 15.4269 9.47424 8.11889C9.47424 6.10409 9.92454 4.19447 10.73 2.48517C5.60094 4.30725 1.92825 9.20347 1.92825 14.9575C1.92825 22.2655 7.85255 28.1898 15.1605 28.1898C20.4537 28.1898 25.021 25.0818 27.1371 20.5912Z"
fill="white" />
</svg>
</li>
</ul>
</div>
</header>
<div class="wrapper">
<aside class="aside-topics">
<div id="searchbox">
<!-- Search Input and Button -->
<input type="text" id="searchInput" placeholder="Search">
<button id="searchButton">
<svg width="14" height="14" viewBox="0 0 20 20" aria-hidden="true">
<path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</button>
<kbd id="searchKeys"></kbd>
<div id="searchResults"></div>
</div>
<div class="title">
<a href="index.html">
<img src="assets/images/logo.svg" alt="">
<span>Documentation</span>
</a>
<div class="aside-topics-close">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 -960 960 960">
<path
d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"
fill="white" />
</svg>
</div>
</div>
<nav>
<div class="group">
<section>
<div class="items">
<a class="link" href="introduction.html">Introduction</a>
<a class="link" href="installing-v-from-source.html">Installing V from source</a>
<a class="link" href="upgrading-v-to-latest-version.html">Upgrading V to latest version</a>
<a class="link" href="packaging-v-for-distribution.html">Packaging V for distribution</a>
<a class="link" href="getting-started.html">Getting started</a>
<a class="link" href="hello-world.html">Hello World</a>
<a class="link" href="running-a-project-folder-with-several-files.html">Running a project folder with several files</a>
<a class="link" href="comments.html">Comments</a>
<a class="link" href="functions.html">Functions</a>
<a class="link subtopic" href="functions.html#hoisting"> Hoisting</a>
<a class="link subtopic" href="functions.html#returning-multiple-values"> Returning multiple values</a>
<a class="link" href="symbol-visibility.html">Symbol visibility</a>
<a class="link" href="variables.html">Variables</a>
<a class="link subtopic" href="variables.html#mutable-variables"> Mutable variables</a>
<a class="link subtopic" href="variables.html#initialization-vs-assignment"> Initialization vs assignment</a>
<a class="link subtopic" href="variables.html#warnings-and-declaration-errors"> Warnings and declaration errors</a>
<a class="link" href="v-types.html">V Types</a>
<a class="link subtopic" href="v-types.html#primitive-types"> Primitive types</a>
<a class="link subtopic" href="v-types.html#strings"> Strings</a>
<a class="link subtopic" href="v-types.html#runes"> Runes</a>
<a class="link subtopic" href="v-types.html#numbers"> Numbers</a>
<a class="link subtopic" href="v-types.html#arrays"> Arrays</a>
<a class="link subtopic" href="v-types.html#fixed-size-arrays"> Fixed size arrays</a>
<a class="link subtopic" href="v-types.html#maps"> Maps</a>
<a class="link subtopic" href="v-types.html#map-update-syntax"> Map update syntax</a>
<a class="link" href="module-imports.html">Module imports</a>
<a class="link subtopic" href="module-imports.html#selective-imports"> Selective imports</a>
<a class="link subtopic" href="module-imports.html#module-hierarchy"> Module hierarchy</a>
<a class="link subtopic" href="module-imports.html#module-import-aliasing"> Module import aliasing</a>
<a class="link active" href="statements-&-expressions.html">Statements & expressions</a>
<a class="link subtopic" href="statements-&-expressions.html#if"> If</a>
<a class="link subtopic" href="statements-&-expressions.html#match"> Match</a>
<a class="link subtopic" href="statements-&-expressions.html#in-operator"> In operator</a>
<a class="link subtopic" href="statements-&-expressions.html#for-loop"> For loop</a>
<a class="link subtopic" href="statements-&-expressions.html#defer"> Defer</a>
<a class="link subtopic" href="statements-&-expressions.html#goto"> Goto</a>
<a class="link" href="structs.html">Structs</a>
<a class="link subtopic" href="structs.html#heap-structs"> Heap structs</a>
<a class="link subtopic" href="structs.html#default-field-values"> Default field values</a>
<a class="link subtopic" href="structs.html#required-fields"> Required fields</a>
<a class="link subtopic" href="structs.html#short-struct-literal-syntax"> Short struct literal syntax</a>
<a class="link subtopic" href="structs.html#struct-update-syntax"> Struct update syntax</a>
<a class="link subtopic" href="structs.html#trailing-struct-literal-arguments"> Trailing struct literal arguments</a>
<a class="link subtopic" href="structs.html#access-modifiers"> Access modifiers</a>
<a class="link subtopic" href="structs.html#anonymous-structs"> Anonymous structs</a>
<a class="link subtopic" href="structs.html#static-type-methods"> Static type methods</a>
<a class="link subtopic" href="structs.html#noinit-structs"> [noinit] structs</a>
<a class="link subtopic" href="structs.html#methods"> Methods</a>
<a class="link subtopic" href="structs.html#embedded-structs"> Embedded structs</a>
<a class="link" href="unions.html">Unions</a>
<a class="link" href="functions-2.html">Functions 2</a>
<a class="link subtopic" href="functions-2.html#immutable-function-args-by-default"> Immutable function args by default</a>
<a class="link subtopic" href="functions-2.html#mutable-arguments"> Mutable arguments</a>
<a class="link subtopic" href="functions-2.html#variable-number-of-arguments"> Variable number of arguments</a>
<a class="link subtopic" href="functions-2.html#anonymous-&-higher-order-functions"> Anonymous & higher order functions</a>
<a class="link subtopic" href="functions-2.html#closures"> Closures</a>
<a class="link subtopic" href="functions-2.html#parameter-evaluation-order"> Parameter evaluation order</a>
<a class="link" href="references.html">References</a>
<a class="link" href="constants.html">Constants</a>
<a class="link subtopic" href="constants.html#required-module-prefix"> Required module prefix</a>
<a class="link" href="builtin-functions.html">Builtin functions</a>
<a class="link subtopic" href="builtin-functions.html#println"> println</a>
<a class="link subtopic" href="builtin-functions.html#printing-custom-types"> Printing custom types</a>
<a class="link subtopic" href="builtin-functions.html#dumping-expressions-at-runtime"> Dumping expressions at runtime</a>
<a class="link" href="modules.html">Modules</a>
<a class="link subtopic" href="modules.html#create-modules"> Create modules</a>
<a class="link subtopic" href="modules.html#special-considerations-for-project-folders"> Special considerations for project folders</a>
<a class="link subtopic" href="modules.html#init-functions"> init functions</a>
<a class="link subtopic" href="modules.html#cleanup-functions"> cleanup functions</a>
<a class="link" href="type-declarations.html">Type Declarations</a>
<a class="link subtopic" href="type-declarations.html#type-aliases"> Type aliases</a>
<a class="link subtopic" href="type-declarations.html#enums"> Enums</a>
<a class="link subtopic" href="type-declarations.html#function-types"> Function Types</a>
<a class="link subtopic" href="type-declarations.html#interfaces"> Interfaces</a>
<a class="link subtopic" href="type-declarations.html#sum-types"> Sum types</a>
<a class="link subtopic" href="type-declarations.html#optionresult-types-and-error-handling"> Option/Result types and error handling</a>
<a class="link subtopic" href="type-declarations.html#custom-error-types"> Custom error types</a>
<a class="link subtopic" href="type-declarations.html#generics"> Generics</a>
<a class="link" href="concurrency.html">Concurrency</a>
<a class="link subtopic" href="concurrency.html#spawning-concurrent-tasks"> Spawning Concurrent Tasks</a>
<a class="link subtopic" href="concurrency.html#channels"> Channels</a>
<a class="link subtopic" href="concurrency.html#shared-objects"> Shared Objects</a>
<a class="link" href="json.html">JSON</a>
<a class="link subtopic" href="json.html#decoding-json"> Decoding JSON</a>
<a class="link subtopic" href="json.html#encoding-json"> Encoding JSON</a>
<a class="link" href="testing.html">Testing</a>
<a class="link subtopic" href="testing.html#asserts"> Asserts</a>
<a class="link subtopic" href="testing.html#asserts-with-an-extra-message"> Asserts with an extra message</a>
<a class="link subtopic" href="testing.html#asserts-that-do-not-abort-your-program"> Asserts that do not abort your program</a>
<a class="link subtopic" href="testing.html#test-files"> Test files</a>
<a class="link subtopic" href="testing.html#running-tests"> Running tests</a>
<a class="link" href="memory-management.html">Memory management</a>
<a class="link subtopic" href="memory-management.html#control"> Control</a>
<a class="link subtopic" href="memory-management.html#stack-and-heap"> Stack and Heap</a>
<a class="link" href="orm.html">ORM</a>
<a class="link" href="writing-documentation.html">Writing Documentation</a>
<a class="link subtopic" href="writing-documentation.html#newlines-in-documentation-comments"> Newlines in Documentation Comments</a>
<a class="link" href="tools.html">Tools</a>
<a class="link subtopic" href="tools.html#v-fmt"> v fmt</a>
<a class="link subtopic" href="tools.html#v-shader"> v shader</a>
<a class="link subtopic" href="tools.html#profiling"> Profiling</a>
<a class="link" href="package-management.html">Package management</a>
<a class="link subtopic" href="package-management.html#package-commands"> Package commands</a>
<a class="link subtopic" href="package-management.html#publish-package"> Publish package</a>
<a class="link" href="attributes.html">Attributes</a>
<a class="link" href="conditional-compilation.html">Conditional compilation</a>
<a class="link subtopic" href="conditional-compilation.html#compile-time-pseudo-variables"> Compile time pseudo variables</a>
<a class="link subtopic" href="conditional-compilation.html#compile-time-reflection"> Compile time reflection</a>
<a class="link subtopic" href="conditional-compilation.html#compile-time-code"> Compile time code</a>
<a class="link subtopic" href="conditional-compilation.html#compile-time-types"> Compile time types</a>
<a class="link subtopic" href="conditional-compilation.html#environment-specific-files"> Environment specific files</a>
<a class="link" href="debugger.html">Debugger</a>
<a class="link" href="call-stack.html">Call stack</a>
<a class="link" href="trace.html">Trace</a>
<a class="link" href="memory-unsafe-code.html">Memory-unsafe code</a>
<a class="link" href="structs-with-reference-fields.html">Structs with reference fields</a>
<a class="link" href="sizeof-and-__offsetof.html">sizeof and __offsetof</a>
<a class="link" href="limited-operator-overloading.html">Limited operator overloading</a>
<a class="link subtopic" href="limited-operator-overloading.html#implicitly-generated-overloads"> Implicitly generated overloads</a>
<a class="link subtopic" href="limited-operator-overloading.html#restriction"> Restriction</a>
<a class="link" href="performance-tuning.html">Performance tuning</a>
<a class="link subtopic" href="performance-tuning.html#tuning-operations-details"> Tuning operations details</a>
<a class="link" href="atomics.html">Atomics</a>
<a class="link" href="global-variables.html">Global Variables</a>
<a class="link" href="cross-compilation.html">Cross compilation</a>
<a class="link" href="debugging.html">Debugging</a>
<a class="link subtopic" href="debugging.html#c-backend-binaries-(default)"> C Backend binaries (Default)</a>
<a class="link subtopic" href="debugging.html#native-backend-binaries"> Native Backend binaries</a>
<a class="link subtopic" href="debugging.html#javascript-backend"> Javascript Backend</a>
<a class="link" href="v-and-c.html">V and C</a>
<a class="link subtopic" href="v-and-c.html#calling-c-from-v"> Calling C from V</a>
<a class="link subtopic" href="v-and-c.html#calling-v-from-c"> Calling V from C</a>
<a class="link subtopic" href="v-and-c.html#passing-c-compilation-flags"> Passing C compilation flags</a>
<a class="link subtopic" href="v-and-c.html#pkgconfig"> pkgconfig</a>
<a class="link subtopic" href="v-and-c.html#including-c-code"> Including C code</a>
<a class="link subtopic" href="v-and-c.html#c-types"> C types</a>
<a class="link subtopic" href="v-and-c.html#c-declarations"> C Declarations</a>
<a class="link subtopic" href="v-and-c.html#export-to-shared-library"> Export to shared library</a>
<a class="link subtopic" href="v-and-c.html#translating-c-to-v"> Translating C to V</a>
<a class="link subtopic" href="v-and-c.html#working-around-c-issues"> Working around C issues</a>
<a class="link" href="other-v-features.html">Other V Features</a>
<a class="link subtopic" href="other-v-features.html#inline-assembly"> Inline assembly</a>
<a class="link subtopic" href="other-v-features.html#hot-code-reloading"> Hot code reloading</a>
<a class="link subtopic" href="other-v-features.html#cross-platform-shell-scripts-in-v"> Cross-platform shell scripts in V</a>
<a class="link subtopic" href="other-v-features.html#vsh-scripts-with-no-extension"> Vsh scripts with no extension</a>
<a class="link" href="appendix-i-keywords.html">Appendix I: Keywords</a>
<a class="link" href="appendix-ii-operators.html">Appendix II: Operators</a>
<a class="link" href="other-online-resources.html">Other online resources</a>
<a class="link subtopic" href="other-online-resources.html#v-contributing-guide"> V contributing guide</a>
<a class="link subtopic" href="other-online-resources.html#v-language-documentation"> V language documentation</a>
<a class="link subtopic" href="other-online-resources.html#v-standard-module-documentation"> V standard module documentation</a>
<a class="link subtopic" href="other-online-resources.html#v-online-playground"> V online playground</a>
<a class="link subtopic" href="other-online-resources.html#awesome-v"> Awesome V</a>
<a class="link subtopic" href="other-online-resources.html#the-v-language-discord"> The V language Discord</a>
</div>
</section>
</div>
</nav>
</aside>
<article>
<div class="container">
<div class="content">
<div class="content-container">
<main>
<h1 class="main">Statements & expressions</h1>
<h2 id="if">If <a href="statements-&-expressions.html#if" class="header-anchor" aria-hidden="true">#</a></h2>
<div class="language-v">a := 10
b := 20
if a < b {
println('${a} < ${b}')
} else if a > b {
println('${a} > ${b}')
} else {
println('${a} == ${b}')
}
</div>
<p><code>if</code> statements are pretty straightforward and similar to most other languages.
Unlike other C-like languages,
there are no parentheses surrounding the condition and the braces are always required.</p>
<h3 id="if-expressions"><code>If</code> expressions <a href="statements-&-expressions.html#if-expressions" class="header-anchor" aria-hidden="true">#</a></h3>
<p>Unlike C, V does not have a ternary operator, that would allow you to do: <code>x = c ? 1 : 2</code> .
Instead, it has a bit more verbose, but also clearer to read, ability to use <code>if</code> as an
expression. The direct translation in V of the ternary construct above, assuming <code>c</code> is a
boolean condition, would be: <code>x = if c { 1 } else { 2 }</code>.</p>
<p>Here is another example:</p>
<div class="language-v">num := 777
s := if num % 2 == 0 { 'even' } else { 'odd' }
println(s)
// "odd"
</div>
<p>You can use multiple statements in each of the branches of an <code>if</code> expression, followed by a final
value, that will become the value of the entire <code>if</code> expression, when it takes that branch:</p>
<div class="language-v">n := arguments().len
x := if n > 2 {
dump(arguments())
42
} else {
println('something else')
100
}
dump(x)
</div>
<h3 id="if-unwrapping"><code>If</code> unwrapping <a href="statements-&-expressions.html#if-unwrapping" class="header-anchor" aria-hidden="true">#</a></h3>
<p>Anywhere you can use <code>or {}</code>, you can also use "if unwrapping". This binds the unwrapped value
of an expression to a variable when that expression is not none nor an error.</p>
<div class="language-v">m := {
'foo': 'bar'
}
// handle missing keys
if v := m['foo'] {
println(v) // bar
} else {
println('not found')
}
</div>
<div class="language-v">fn res() !int {
return 42
}
// functions that return a result type
if v := res() {
println(v)
}
</div>
<div class="language-v">struct User {
name string
}
arr := [User{'John'}]
// if unwrapping with assignment of a variable
u_name := if v := arr[0] {
v.name
} else {
'Unnamed'
}
println(u_name) // John
</div>
<h3 id="type-checks-and-casts">Type checks and casts <a href="statements-&-expressions.html#type-checks-and-casts" class="header-anchor" aria-hidden="true">#</a></h3>
<p>You can check the current type of a sum type using <code>is</code> and its negated form <code>!is</code>.</p>
<p>You can do it either in an <code>if</code>:</p>
<div class="language-v">struct Abc {
val string
}
struct Xyz {
foo string
}
type Alphabet = Abc | Xyz
x := Alphabet(Abc{'test'}) // sum type
if x is Abc {
// x is automatically cast to Abc and can be used here
println(x)
}
if x !is Abc {
println('Not Abc')
}
</div>
<p>or using <code>match</code>:</p>
<div class="language-v">match x {
Abc {
// x is automatically cast to Abc and can be used here
println(x)
}
Xyz {
// x is automatically cast to Xyz and can be used here
println(x)
}
}
</div>
<p>This works also with struct fields:</p>
<div class="language-v">struct MyStruct {
x int
}
struct MyStruct2 {
y string
}
type MySumType = MyStruct | MyStruct2
struct Abc {
bar MySumType
}
x := Abc{
bar: MyStruct{123} // MyStruct will be converted to MySumType type automatically
}
if x.bar is MyStruct {
// x.bar is automatically cast
println(x.bar)
} else if x.bar is MyStruct2 {
new_var := x.bar as MyStruct2
// ... or you can use `as` to create a type cast an alias manually:
println(new_var)
}
match x.bar {
MyStruct {
// x.bar is automatically cast
println(x.bar)
}
else {}
}
</div>
<p>Mutable variables can change, and doing a cast would be unsafe.
However, sometimes it's useful to type cast despite mutability.
In such cases the developer must mark the expression with the <code>mut</code> keyword
to tell the compiler that they know what they're doing.</p>
<p>It works like this:</p>
<div class="language-v">mut x := MySumType(MyStruct{123})
if mut x is MyStruct {
// x is cast to MyStruct even if it's mutable
// without the mut keyword that wouldn't work
println(x)
}
// same with match
match mut x {
MyStruct {
// x is cast to MyStruct even if it's mutable
// without the mut keyword that wouldn't work
println(x)
}
}
</div>
<h2 id="match">Match <a href="statements-&-expressions.html#match" class="header-anchor" aria-hidden="true">#</a></h2>
<div class="language-v">os := 'windows'
print('V is running on ')
match os {
'darwin' { println('macOS.') }
'linux' { println('Linux.') }
else { println(os) }
}
</div>
<p>A match statement is a shorter way to write a sequence of <code>if - else</code> statements.
When a matching branch is found, the following statement block will be run.
The else branch will be run when no other branches match.</p>
<div class="language-v">number := 2
s := match number {
1 { 'one' }
2 { 'two' }
else { 'many' }
}
</div>
<p>A match statement can also to be used as an <code>if - else if - else</code> alternative:</p>
<div class="language-v">match true {
2 > 4 { println('if') }
3 == 4 { println('else if') }
2 == 2 { println('else if2') }
else { println('else') }
}
// 'else if2' should be printed
</div>
<p>or as an <code>unless</code> alternative: <a href="https://www.tutorialspoint.com/ruby/ruby_if_else.htm">unless Ruby</a></p>
<div class="language-v">match false {
2 > 4 { println('if') }
3 == 4 { println('else if') }
2 == 2 { println('else if2') }
else { println('else') }
}
// 'if' should be printed
</div>
<p>A match expression returns the value of the final expression from the matching branch.</p>
<div class="language-v">enum Color {
red
blue
green
}
fn is_red_or_blue(c Color) bool {
return match c {
.red, .blue { true } // comma can be used to test multiple values
.green { false }
}
}
</div>
<p>A match statement can also be used to branch on the variants of an <code>enum</code>
by using the shorthand <code>.variant_here</code> syntax. An <code>else</code> branch is not allowed
when all the branches are exhaustive.</p>
<div class="language-v">c := `v`
typ := match c {
`0`...`9` { 'digit' }
`A`...`Z` { 'uppercase' }
`a`...`z` { 'lowercase' }
else { 'other' }
}
println(typ)
// 'lowercase'
</div>
<p>A match statement also can match the variant types of a <code>sumtype</code>. Note that
in that case, the match is exhaustive, since all variant types are mentioned
explicitly, so there is no need for an <code>else{}</code> branch.</p>
<div class="language-v">struct Dog {}
struct Cat {}
struct Veasel {}
type Animal = Dog | Cat | Veasel
a := Animal(Veasel{})
match a {
Dog { println('Bay') }
Cat { println('Meow') }
Veasel { println('Vrrrrr-eeee') } // see: https://www.youtube.com/watch?v=qTJEDyj2N0Q
}
</div>
<p>You can also use ranges as <code>match</code> patterns. If the value falls within the range
of a branch, that branch will be executed.</p>
<p>Note that the ranges use <code>...</code> (three dots) rather than <code>..</code> (two dots). This is
because the range is <em>inclusive</em> of the last element, rather than exclusive
(as <code>..</code> ranges are). Using <code>..</code> in a match branch will throw an error.</p>
<div class="language-v">const start = 1
const end = 10
c := 2
num := match c {
start...end {
1000
}
else {
0
}
}
println(num)
// 1000
</div>
<p>Constants can also be used in the range branch expressions.</p>
<blockquote class="tip">
<p>[!NOTE]
<code>match</code> as an expression is not usable in <code>for</code> loop and <code>if</code> statements.</p>
</blockquote>
<h2 id="in-operator">In operator <a href="statements-&-expressions.html#in-operator" class="header-anchor" aria-hidden="true">#</a></h2>
<p><code>in</code> allows to check whether an array or a map contains an element.
To do the opposite, use <code>!in</code>.</p>
<div class="language-v">nums := [1, 2, 3]
println(1 in nums) // true
println(4 !in nums) // true
</div>
<blockquote class="tip">
<p>[!NOTE]
<code>in</code> checks if map contains a key, not a value.</p>
</blockquote>
<div class="language-v">m := {
'one': 1
'two': 2
}
println('one' in m) // true
println('three' !in m) // true
</div>
<p>It's also useful for writing boolean expressions that are clearer and more compact:</p>
<div class="language-v">enum Token {
plus
minus
div
mult
}
struct Parser {
token Token
}
parser := Parser{}
if parser.token == .plus || parser.token == .minus || parser.token == .div || parser.token == .mult {
// ...
}
if parser.token in [.plus, .minus, .div, .mult] {
// ...
}
</div>
<p>V optimizes such expressions,
so both <code>if</code> statements above produce the same machine code and no arrays are created.</p>
<h2 id="for-loop">For loop <a href="statements-&-expressions.html#for-loop" class="header-anchor" aria-hidden="true">#</a></h2>
<p>V has only one looping keyword: <code>for</code>, with several forms.</p>
<h3 id="forin"><code>for</code>/<code>in</code> <a href="statements-&-expressions.html#forin" class="header-anchor" aria-hidden="true">#</a></h3>
<p>This is the most common form. You can use it with an array, map or
numeric range.</p>
<h4 id="array-for">Array <code>for</code> <a href="statements-&-expressions.html#array-for" class="header-anchor" aria-hidden="true">#</a></h4>
<div class="language-v">numbers := [1, 2, 3, 4, 5]
for num in numbers {
println(num)
}
names := ['Sam', 'Peter']
for i, name in names {
println('${i}) ${name}')
// Output: 0) Sam
// 1) Peter
}
</div>
<p>The <code>for value in arr</code> form is used for going through elements of an array.
If an index is required, an alternative form <code>for index, value in arr</code> can be used.</p>
<p>Note that the value is read-only.
If you need to modify the array while looping, you need to declare the element as mutable:</p>
<div class="language-v">mut numbers := [0, 1, 2]
for mut num in numbers {
num++
}
println(numbers) // [1, 2, 3]
</div>
<p>When an identifier is just a single underscore, it is ignored.</p>
<h4 id="custom-iterators">Custom iterators <a href="statements-&-expressions.html#custom-iterators" class="header-anchor" aria-hidden="true">#</a></h4>
<p>Types that implement a <code>next</code> method returning an <code>Option</code> can be iterated
with a <code>for</code> loop.</p>
<div class="language-v">struct SquareIterator {
arr []int
mut:
idx int
}
fn (mut iter SquareIterator) next() ?int {
if iter.idx >= iter.arr.len {
return none
}
defer {
iter.idx++
}
return iter.arr[iter.idx] * iter.arr[iter.idx]
}
nums := [1, 2, 3, 4, 5]
iter := SquareIterator{
arr: nums
}
for squared in iter {
println(squared)
}
</div>
<p>The code above prints:</p>
<pre><code>1
4
9
16
25
</code></pre>
<h4 id="map-for">Map <code>for</code> <a href="statements-&-expressions.html#map-for" class="header-anchor" aria-hidden="true">#</a></h4>
<div class="language-v">m := {
'one': 1
'two': 2
}
for key, value in m {
println('${key} -> ${value}')
// Output: one -> 1
// two -> 2
}
</div>
<p>Either key or value can be ignored by using a single underscore as the identifier.</p>
<div class="language-v">m := {
'one': 1
'two': 2
}
// iterate over keys
for key, _ in m {
println(key)
// Output: one
// two
}
// iterate over values
for _, value in m {
println(value)
// Output: 1
// 2
}
</div>
<h4 id="range-for">Range <code>for</code> <a href="statements-&-expressions.html#range-for" class="header-anchor" aria-hidden="true">#</a></h4>
<div class="language-v">// Prints '01234'
for i in 0 .. 5 {
print(i)
}
</div>
<p><code>low..high</code> means an <em>exclusive</em> range, which represents all values
from <code>low</code> up to <em>but not including</em> <code>high</code>.</p>
<blockquote class="tip">
<p>[!NOTE]
This exclusive range notation and zero-based indexing follow principles of
logical consistency and error reduction. As Edsger W. Dijkstra outlines in
'Why Numbering Should Start at Zero'
(<a href="https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html">EWD831</a>),
zero-based indexing aligns the index with the preceding elements in a sequence,
simplifying handling and minimizing errors, especially with adjacent subsequences.
This logical and efficient approach shapes our language design, emphasizing clarity
and reducing confusion in programming.</p>
</blockquote>
<h3 id="condition-for">Condition <code>for</code> <a href="statements-&-expressions.html#condition-for" class="header-anchor" aria-hidden="true">#</a></h3>
<div class="language-v">mut sum := 0
mut i := 0
for i <= 100 {
sum += i
i++
}
println(sum) // "5050"
</div>
<p>This form of the loop is similar to <code>while</code> loops in other languages.
The loop will stop iterating once the boolean condition evaluates to false.
Again, there are no parentheses surrounding the condition, and the braces are always required.</p>
<h3 id="bare-for">Bare <code>for</code> <a href="statements-&-expressions.html#bare-for" class="header-anchor" aria-hidden="true">#</a></h3>
<div class="language-v">mut num := 0
for {
num += 2
if num >= 10 {
break
}
}
println(num) // "10"
</div>
<p>The condition can be omitted, resulting in an infinite loop.</p>
<h3 id="c-for">C <code>for</code> <a href="statements-&-expressions.html#c-for" class="header-anchor" aria-hidden="true">#</a></h3>
<div class="language-v">for i := 0; i < 10; i += 2 {
// Don't print 6
if i == 6 {
continue
}
println(i)
}
</div>
<p>Finally, there's the traditional C style <code>for</code> loop. It's safer than the <code>while</code> form
because with the latter it's easy to forget to update the counter and get
stuck in an infinite loop.</p>
<p>Here <code>i</code> doesn't need to be declared with <code>mut</code> since it's always going to be mutable by definition.</p>
<h3 id="labelled-break-&-continue">Labelled break & continue <a href="#labelled-break-&-continue" class="header-anchor" aria-hidden="true">#</a></h3>
<p><code>break</code> and <code>continue</code> control the innermost <code>for</code> loop by default.
You can also use <code>break</code> and <code>continue</code> followed by a label name to refer to an outer <code>for</code>
loop:</p>
<div class="language-v">outer: for i := 4; true; i++ {
println(i)
for {
if i < 7 {
continue outer
} else {
break outer
}
}
}
</div>
<p>The label must immediately precede the outer loop.
The above code prints:</p>
<pre><code>4
5
6
7
</code></pre>
<h2 id="defer">Defer <a href="statements-&-expressions.html#defer" class="header-anchor" aria-hidden="true">#</a></h2>
<p>A defer statement defers the execution of a block of statements
until the surrounding function returns.</p>
<div class="language-v">import os
fn read_log() {
mut ok := false
mut f := os.open('log.txt') or { panic(err) }
defer {
f.close()
}
// ...
if !ok {
// defer statement will be called here, the file will be closed
return
}
// ...
// defer statement will be called here, the file will be closed
}
</div>
<p>If the function returns a value the <code>defer</code> block is executed <em>after</em> the return
expression is evaluated:</p>
<div class="language-v">import os
enum State {
normal
write_log
return_error
}
// write log file and return number of bytes written
fn write_log(s State) !int {
mut f := os.create('log.txt')!
defer {
f.close()
}
if s == .write_log {
// `f.close()` will be called after `f.write()` has been
// executed, but before `write_log()` finally returns the
// number of bytes written to `main()`
return f.writeln('This is a log file')
} else if s == .return_error {
// the file will be closed after the `error()` function
// has returned - so the error message will still report
// it as open
return error('nothing written; file open: ${f.is_opened}')
}
// the file will be closed here, too
return 0
}
fn main() {
n := write_log(.return_error) or {
println('Error: ${err}')
0
}
println('${n} bytes written')
}
</div>
<p>To access the result of the function inside a <code>defer</code> block the <code>$res()</code> expression can be used.
<code>$res()</code> is only used when a single value is returned, while on multi-return the <code>$res(idx)</code>
is parameterized.</p>
<div class="language-v">fn (mut app App) auth_middleware() bool {
defer {
if !$res() {
app.response.status_code = 401
app.response.body = 'Unauthorized'
}
}
header := app.get_header('Authorization')
if header == '' {
return false
}
return true
}
fn (mut app App) auth_with_user_middleware() (bool, string) {
defer {
if !$res(0) {
app.response.status_code = 401
app.response.body = 'Unauthorized'
} else {
app.user = $res(1)
}
}
header := app.get_header('Authorization')
if header == '' {
return false, ''
}
return true, 'TestUser'
}
</div>
<h2 id="goto">Goto <a href="statements-&-expressions.html#goto" class="header-anchor" aria-hidden="true">#</a></h2>
<p>V allows unconditionally jumping to a label with <code>goto</code>. The label name must be contained
within the same function as the <code>goto</code> statement. A program may <code>goto</code> a label outside
or deeper than the current scope. <code>goto</code> allows jumping past variable initialization or
jumping back to code that accesses memory that has already been freed, so it requires
<code>unsafe</code>.</p>
<div class="language-v">if x {
// ...
if y {
unsafe {
goto my_label
}
}
// ...
}
my_label:
</div>
<p><code>goto</code> should be avoided, particularly when <code>for</code> can be used instead.
<a href="statements-&-expressions.html#labelled-break-&-continue">Labelled break/continue</a> can be used to break out of
a nested loop, and those do not risk violating memory-safety.</p>
</main>
<footer>
<div class="edit-info">
<div class="edit-link">
<a class="link edit-link-button"
href="https://github.com/vlang/v/edit/master/doc/docs.md#L1673"
target="_blank" rel="noreferrer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
class="edit-link-icon">
<path
d="M18,23H4c-1.7,0-3-1.3-3-3V6c0-1.7,1.3-3,3-3h7c0.6,0,1,0.4,1,1s-0.4,1-1,1H4C3.4,5,3,5.4,3,6v14c0,0.6,0.4,1,1,1h14c0.6,0,1-0.4,1-1v-7c0-0.6,0.4-1,1-1s1,0.4,1,1v7C21,21.7,19.7,23,18,23z">
</path>
<path
d="M8,17c-0.3,0-0.5-0.1-0.7-0.3C7,16.5,6.9,16.1,7,15.8l1-4c0-0.2,0.1-0.3,0.3-0.5l9.5-9.5c1.2-1.2,3.2-1.2,4.4,0c1.2,1.2,1.2,3.2,0,4.4l-9.5,9.5c-0.1,0.1-0.3,0.2-0.5,0.3l-4,1C8.2,17,8.1,17,8,17zM9.9,12.5l-0.5,2.1l2.1-0.5l9.3-9.3c0.4-0.4,0.4-1.1,0-1.6c-0.4-0.4-1.2-0.4-1.6,0l0,0L9.9,12.5z M18.5,2.5L18.5,2.5L18.5,2.5z">
</path>
</svg>
Edit this page on GitHub
</a>
</div>
<div class="last-updated">
<time datetime="2024-11-27T19:07:56.421Z">Last updated:
2024-11-27 21:07:56, V Commit: <a
href="https://github.com/vlang/v/commit/066384ce8c13bcac052d60f1983f40674ba9b698">066384c</a></time>
</div>
</div>
<!-- only-prev or only-next -->
<div class="prev-next">
<div class="page prev-page">
<a class="page-link" href="module-imports.html">
<span class="desc">Previous page</span>
<span class="title">Module imports</span>
</a>
</div>
<div class="page next-page">
<a class="page-link" href="structs.html">
<span class="desc">Next page</span>
<span class="title">Structs</span>
</a>
</div>
</div>
</footer>
</div>
</div>
<div class="aside">
<div class="aside-content">
<div class="aside-container">
<div class="title">On this page</div>
<nav>
<ul>
<li class="active">
<a href="#if">If</a>
</li>
<li class="active">
<a href="#match">Match</a>
</li>
<li class="active">
<a href="#in-operator">In operator</a>
</li>
<li class="active">
<a href="#for-loop">For loop</a>
</li>
<li class="active">
<a href="#defer">Defer</a>
</li>
<li class="active">
<a href="#goto">Goto</a>
</li>
</ul>
</nav>
</div>
<div class="aside-footer"></div>
</div>
</div>
</div>
</article>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const currentNavigationItem = document.querySelector(".link.active");
if (currentNavigationItem !== null) {
currentNavigationItem.scrollIntoView({ block: "center", behavior: "auto" });
}
})
</script>
<script src="assets/scripts/vlang-playground.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const playgroundElements = [...document.querySelectorAll(".language-v"), ...document.querySelectorAll(".language-c")];
playgroundElements.forEach(playgroundElement => {
const playground = Playground.create(playgroundElement, {
fontSize: "14px",
highlightOnly: true,
showFooter: false,
showLineNumbers: false,
});
playgrounds.push(playground);
});
})
</script>
<script src="assets/scripts/theme.js"></script>
<script>
document.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
window.open("module-imports.html", "_self")
}
if (event.key === "ArrowRight") {
window.open("structs.html", "_self")
}
})
//window.onload = () => {
//const html = document.querySelector("html");
//html.style.opacity = '1'
//}
</script>
<script>
document.getElementsByClassName("aside-topics-open")[0].addEventListener("click", (event) => {
document.getElementsByClassName("aside-topics")[0].style.setProperty('display', 'block')
})
document.getElementsByClassName("aside-topics-close")[0].addEventListener("click", (event) => {
document.getElementsByClassName("aside-topics")[0].style.setProperty('display', 'none')
})
</script>
<script src="assets/scripts/titles_to_fnames.js"></script>
<script src="assets/scripts/search.js"></script>
</body>
</html>