v2 / vlib / v / gen / c / testdata / logical_and_short_circuit.vv
31 lines · 29 sloc · 864 bytes · 42d5c0b2e7231ebde9992d902ec747e974c57cd7
Raw
1fn print_true(i int) bool {
2 println(i)
3 return true
4}
5
6const other_list = [3, 4]
7
8fn main() {
9 list := [1, 2, 3]
10 index := 3
11 if index < list.len && list[index] == 3 {
12 println('Index is within bounds and value is 3')
13 } else {
14 println('Index is out of bounds or value is not 3')
15 }
16 if index < list.len && print_true(list[index]) {
17 println('Index is within bounds')
18 } else {
19 println('Index is out of bounds')
20 }
21 if index < list.len && other_list.contains(list[index]) {
22 println('Index is within bounds and value is in other_list')
23 } else {
24 println('Index is out of bounds or value is not in other_list')
25 }
26 if index < list.len && (other_list.contains(list[index]) || other_list.contains(list[index])) {
27 println('Index is within bounds and value is in other_list')
28 } else {
29 println('Index is out of bounds or value is not in other_list')
30 }
31}
32