Files
hello-algo/ru/codes/go/chapter_computational_complexity/iteration.go
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

60 lines
1.3 KiB
Go

// File: iteration.go
// Created Time: 2023-08-28
// Author: Reanon (793584285@qq.com)
package chapter_computational_complexity
import "fmt"
/* Цикл for */
func forLoop(n int) int {
res := 0
// Циклическое суммирование 1, 2, ..., n-1, n
for i := 1; i <= n; i++ {
res += i
}
return res
}
/* Цикл while */
func whileLoop(n int) int {
res := 0
// Инициализация условной переменной
i := 1
// Циклическое суммирование 1, 2, ..., n-1, n
for i <= n {
res += i
// Обновить условную переменную
i++
}
return res
}
/* Цикл while (двойное обновление) */
func whileLoopII(n int) int {
res := 0
// Инициализация условной переменной
i := 1
// Циклическое суммирование 1, 4, 10, ...
for i <= n {
res += i
// Обновить условную переменную
i++
i *= 2
}
return res
}
/* Двойной цикл for */
func nestedForLoop(n int) string {
res := ""
// Цикл по i = 1, 2, ..., n-1, n
for i := 1; i <= n; i++ {
for j := 1; j <= n; j++ {
// Цикл по j = 1, 2, ..., n-1, n
res += fmt.Sprintf("(%d, %d), ", i, j)
}
}
return res
}