From e9dc7796a89cf850ec6a7f3808672a3e1e95ca12 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Sun, 24 Dec 2023 00:51:19 -0300 Subject: [PATCH 1/2] Basic for structure implemented on 06_repetitions and for.v file --- 04_conditions/if.v | 49 ------------------------------------------- 04_conditions/match.v | 4 ---- 06_repetitions/for.v | 18 ++++++++++++++++ 3 files changed, 18 insertions(+), 53 deletions(-) delete mode 100644 04_conditions/if.v delete mode 100644 04_conditions/match.v create mode 100644 06_repetitions/for.v diff --git a/04_conditions/if.v b/04_conditions/if.v deleted file mode 100644 index 56ffc7c..0000000 --- a/04_conditions/if.v +++ /dev/null @@ -1,49 +0,0 @@ - - -pub fn main() -{ - mut a := 10 - mut b := 20 - - // Simple if structure - if a < b - { - println("${a} é menor do que ${b}") - }else if(a > b) - { - println("${a} é maior do que ${b}") - }else - { - println("${a} é igual a ${b}") - } - - num := 777 - - s := if num % 2 == 0 { 'even' } else { 'odd' } - println(s) - - - // ================================================================ // - - m := { - 'foor' : 'bar' - } - - if v := m['foo'] - { - println(v) - }else - { - println('not found') - } - - if c := res() - { - println(c) - } -} - -fn res() !int -{ - return 42 -} \ No newline at end of file diff --git a/04_conditions/match.v b/04_conditions/match.v deleted file mode 100644 index 39a5f15..0000000 --- a/04_conditions/match.v +++ /dev/null @@ -1,4 +0,0 @@ -pub fn main() -{ - println('oi') -} \ No newline at end of file diff --git a/06_repetitions/for.v b/06_repetitions/for.v new file mode 100644 index 0000000..fed3558 --- /dev/null +++ b/06_repetitions/for.v @@ -0,0 +1,18 @@ + +pub fn main() { + + // ==================================== // + // Basic for + + numbers := [1,2,3,4,5] + + for num in numbers { + println(num) + } + + names := ['Sam', 'Peter'] + + for i, name in names { + println("${i} - ${name}") + } +} \ No newline at end of file From 4968a0b099a67adfc3e8fca72eed59ff2ae48929 Mon Sep 17 00:00:00 2001 From: Vinicius Silva Date: Sun, 24 Dec 2023 00:54:39 -0300 Subject: [PATCH 2/2] Mutable for implemented --- 06_repetitions/for.v | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/06_repetitions/for.v b/06_repetitions/for.v index fed3558..db85909 100644 --- a/06_repetitions/for.v +++ b/06_repetitions/for.v @@ -15,4 +15,18 @@ pub fn main() { for i, name in names { println("${i} - ${name}") } + + // ==================================== // + + mut numbers2 := [1,2,3,4,5] + + for mut num in numbers2 { + num++ + } + + println(numbers2) + + // ==================================== // + + } \ No newline at end of file