diff --git a/README.md b/README.md index a9781427..df806ad1 100644 --- a/README.md +++ b/README.md @@ -193,8 +193,8 @@ while x == y { The `while` statement doesn't yield anything; it only evaluates to `()` of unit type. MoonBit also provides the `break` and `continue` statements for controlling the flow of a loop. ```rust -var i = 0 -var n = 0 +let mut i = 0 +let mut n = 0 while i < 10 { i = i + 1 @@ -214,7 +214,7 @@ println(n) // outputs 25 The `while` loop can have an optional "continue" block after the loop condition, separated by comma. It is executed _after_ the body of every iteration, _before_ the condition of next iteration: ```rust -var i = 0 +let mut i = 0 while i < 10, i = i + 1 { println(i) } // outputs 0 to 9 @@ -223,7 +223,7 @@ while i < 10, i = i + 1 { If there are multiple statements in the continue block, they must be wrapped in braces. `continue` statement in the loop body will not skip continue block. For example, the following code will output all odd numbers smaller than 10: ```rust -var i = 1 +let mut i = 1 while i < 10, i = i + 1 { if (i % 2 == 0) { continue @@ -347,7 +347,7 @@ A variable can be declared as mutable or immutable using the keywords `var` or ` let zero = 0 fn init { - var i = 10 + let mut i = 10 i = 20 print(i + zero) } diff --git a/benchmark/fibonacci/README.md b/benchmark/fibonacci/README.md index 14a22512..5764983d 100644 --- a/benchmark/fibonacci/README.md +++ b/benchmark/fibonacci/README.md @@ -24,8 +24,8 @@ func fib(num : Int) -> Int { } pub func test(n : Int, count : Int) -> Int { - var i = 0 - var res = 0 + let mut i = 0 + let mut res = 0 while i < count { res = fib(n) i = i + 1 diff --git a/examples/avl_tree/lib/avl.mbt b/examples/avl_tree/lib/avl.mbt index 2f676424..b14b9941 100644 --- a/examples/avl_tree/lib/avl.mbt +++ b/examples/avl_tree/lib/avl.mbt @@ -165,8 +165,8 @@ pub fn mem[U:Compare](self: T[U], x: U) -> Bool { } fn repeat_str(s: String, n: Int) -> String { - var result = "" - var i = 0 + let mut result = "" + let mut i = 0 while i < n { result = result + s i = i + 1 diff --git a/examples/avl_tree/main/main.mbt b/examples/avl_tree/main/main.mbt index a9bd2aba..cbea2ef2 100644 --- a/examples/avl_tree/main/main.mbt +++ b/examples/avl_tree/main/main.mbt @@ -1,9 +1,9 @@ fn init { - var v : @lib.T[Int] = Empty // Create an empty AVL tree with Int type + let mut v : @lib.T[Int] = Empty // Create an empty AVL tree with Int type let iter = 30 // Add values from 0 to iter-1 to the AVL tree - var i = 0 + let mut i = 0 while i < iter { v = v.add(i) i = i + 1 @@ -15,7 +15,7 @@ fn init { v.print_tree() // Check values from 0 to iter-1 in the AVL tree - var j = 0 + let mut j = 0 while j < iter { if not(v.mem(j)) { println("impossible") @@ -24,7 +24,7 @@ fn init { } // Remove values from 0 to iter-1 from the AVL tree - var k = 0 + let mut k = 0 while k < iter { v = v.remove(k) k = k + 1 diff --git a/examples/buffer/lib/buffer.mbt b/examples/buffer/lib/buffer.mbt index c33fa090..86645d84 100644 --- a/examples/buffer/lib/buffer.mbt +++ b/examples/buffer/lib/buffer.mbt @@ -32,7 +32,7 @@ fn expand_size[T : Default](self : Buffer[T]) { } self.cap = new_capacity let new_data = Array::make(new_capacity, T::default()) - var index = 0 + let mut index = 0 while index < self.len { new_data[index] = self.data[index] index = index + 1 @@ -49,7 +49,7 @@ pub fn append[T : Default](self : Buffer[T], value : T) { } pub fn truncate[T : Default](self : Buffer[T], another : Buffer[T]) { - var index = 0 + let mut index = 0 while index < another.len { if self.len >= self.cap { self.expand_size() @@ -61,7 +61,7 @@ pub fn truncate[T : Default](self : Buffer[T], another : Buffer[T]) { } pub fn clear[T : Default](self : Buffer[T]) { - var index = 0 + let mut index = 0 while index < self.len { self.data[index] = T::default() index = index + 1 @@ -76,7 +76,7 @@ pub fn reset[T : Default](self : Buffer[T], capacity : Int) { } pub fn println[T : Show](self : Buffer[T]) { - var index = 0 + let mut index = 0 print('[') while index < self.len { print(self.data[index].to_string()) diff --git a/examples/buffer/main/main.mbt b/examples/buffer/main/main.mbt index 87e19820..ca030563 100644 --- a/examples/buffer/main/main.mbt +++ b/examples/buffer/main/main.mbt @@ -1,7 +1,7 @@ fn init { let buf : @lib.Buffer[Int] = @lib.Buffer::new(5) println(buf.capacity()) // 5 - var index = 0 + let mut index = 0 while index < 8 { buf.append(index) index = index + 1 diff --git a/examples/bytes-buffer/lib/buffer.mbt b/examples/bytes-buffer/lib/buffer.mbt index 5cdb7189..3f4cb3ae 100644 --- a/examples/bytes-buffer/lib/buffer.mbt +++ b/examples/bytes-buffer/lib/buffer.mbt @@ -30,7 +30,7 @@ fn expand_size(self : Buffer) { (self.data.length() + 1) * 2 } let new_data = Bytes::make(new_capacity, 0) - var index = 0 + let mut index = 0 while index < self.len { new_data[index] = self.data[index] index = index + 1 @@ -55,7 +55,7 @@ pub fn append_int(self : Buffer, value : Int) { } pub fn truncate(self : Buffer, another: Buffer) { - var index = 0 + let mut index = 0 while index < another.len { if self.len >= self.data.length() { self.expand_size() @@ -67,7 +67,7 @@ pub fn truncate(self : Buffer, another: Buffer) { } pub fn clear(self : Buffer) { - var index = 0 + let mut index = 0 while index < self.len { self.data[index] = 0 index = index + 1 diff --git a/examples/game_of_life/lib/draw.mbt b/examples/game_of_life/lib/draw.mbt index b3beb988..3150568a 100644 --- a/examples/game_of_life/lib/draw.mbt +++ b/examples/game_of_life/lib/draw.mbt @@ -19,13 +19,13 @@ let cell_size = 5 pub fn draw_grid(canvas : Canvas_ctx) { canvas.begin_path() canvas.set_stroke_color(0xcccccc) - var i = 0 + let mut i = 0 while i <= 64 { canvas.move_to(i * (cell_size + 1) + 1, 0) canvas.line_to(i * (cell_size + 1) + 1, (cell_size + 1) * 64 + 1) i = i + 1 } - var j = 0 + let mut j = 0 while j <= 64 { canvas.move_to(0, j * (cell_size + 1) + 1) canvas.line_to((cell_size + 1) * 64 + 1, j * (cell_size + 1) + 1) @@ -37,9 +37,9 @@ pub fn draw_grid(canvas : Canvas_ctx) { pub fn draw_cell(canvas : Canvas_ctx, universe : Universe, dead : Int, alive : Int) { canvas.begin_path() - var row = 0 + let mut row = 0 while row < 64 { - var col = 0 + let mut col = 0 while col < 64 { let idx = universe.get_index(row, col) let color = if universe.get_cell(idx) == 0 { diff --git a/examples/game_of_life/lib/game_of_life.mbt b/examples/game_of_life/lib/game_of_life.mbt index 5e840fc4..913193ab 100644 --- a/examples/game_of_life/lib/game_of_life.mbt +++ b/examples/game_of_life/lib/game_of_life.mbt @@ -21,7 +21,7 @@ pub fn new() -> Universe { let width = 64 let height = 64 let cells : Array[Cell] = Array::make(width * height, Dead) - var idx = 0 + let mut idx = 0 while idx < width * height { if idx % 2 == 0 || idx % 7 == 0 { cells[idx] = Alive @@ -53,12 +53,12 @@ pub fn get_cell(self : Universe, idx : Int) -> Int { } fn live_neighbor_count(self : Universe, row : Int, column : Int) -> Int { - var count = 0 + let mut count = 0 let delta_rows = [self.height - 1, 0, 1] let delta_cols = [self.width - 1, 0, 1] - var r = 0 + let mut r = 0 while r < 3 { - var c = 0 + let mut c = 0 while c < 3 { if delta_rows[r] == 0 && delta_cols[c] == 0 { c = c + 1 @@ -77,9 +77,9 @@ fn live_neighbor_count(self : Universe, row : Int, column : Int) -> Int { pub fn tick(self : Universe) { let next : Array[Cell] = Array::make(self.width * self.height, Dead) - var r = 0 + let mut r = 0 while r < self.height { - var c = 0 + let mut c = 0 while c < self.width { let idx = self.get_index(r, c) let cell = self.cells[idx] @@ -105,10 +105,10 @@ pub fn tick(self : Universe) { } pub fn to_string(self : Universe) -> String { - var r = 0 - var cells = "" + let mut r = 0 + let mut cells = "" while r < self.height { - var c = 0 + let mut c = 0 while c < self.width { let idx = self.get_index(r, c) let cell = self.cells[idx] diff --git a/examples/mandelbrot/lib/mandelbrot.mbt b/examples/mandelbrot/lib/mandelbrot.mbt index ca62e5a3..ff27f7bd 100644 --- a/examples/mandelbrot/lib/mandelbrot.mbt +++ b/examples/mandelbrot/lib/mandelbrot.mbt @@ -35,12 +35,12 @@ let roffset : Double = if floor(image_height) % 2 == 0 { } pub fn iter(cx : Double, cy : Double) -> Double { - var x = 0.0 - var y = 0.0 - var newx = 0.0 - var newy = 0.0 - var smodz = 0.0 - var i = 0 + let mut x = 0.0 + let mut y = 0.0 + let mut newx = 0.0 + let mut newy = 0.0 + let mut smodz = 0.0 + let mut i = 0 while i < max_iter_number { newx = x * x - y * y + cx newy = 2.0 * x * y + cy @@ -70,7 +70,7 @@ fn interpolation(f : Double, c0 : Int, c1 : Int) -> Int { pub fn get_color(d : Double) -> Int { if d >= 0.0 { - var k = 0.021 * (d - 1.0 + log(log(128.0)) / log(2.0)) + let mut k = 0.021 * (d - 1.0 + log(log(128.0)) / log(2.0)) k = log(1.0 + k) - 29.0 / 400.0 k = k - float_of_int(floor(k)) k = k * 400.0 @@ -95,12 +95,12 @@ pub fn calc_color(col : Int, row : Int, ox : Double, oy : Double, let pixel_size = width / image_width let cx = (float_of_int(col) - coffset) * pixel_size + ox let cy = (float_of_int(row) - roffset) * pixel_size + oy - var r = 0 - var g = 0 - var b = 0 - var i = -1 + let mut r = 0 + let mut g = 0 + let mut b = 0 + let mut i = -1 while i <= 1 { - var j = -1 + let mut j = -1 while j <= 1 { let d = iter( cx + float_of_int(i) * pixel_size / 3.0, diff --git a/examples/number/lib/number.mbt b/examples/number/lib/number.mbt index 5fd0fa86..27ea34af 100644 --- a/examples/number/lib/number.mbt +++ b/examples/number/lib/number.mbt @@ -49,9 +49,9 @@ pub fn parse_int(s : String) -> Option[Int] { let char_0 = 0x30 let char_u_a = 0x41 let char_a = 0x61 - var index = 0 - var is_negative = false - var result_digit = 0 + let mut index = 0 + let mut is_negative = false + let mut result_digit = 0 if s[index] == '-' { index = index + 1 is_negative = true diff --git a/examples/palindrome_string/lib/str_iter.mbt b/examples/palindrome_string/lib/str_iter.mbt index d6c6236b..77cf80c6 100644 --- a/examples/palindrome_string/lib/str_iter.mbt +++ b/examples/palindrome_string/lib/str_iter.mbt @@ -1,6 +1,6 @@ pub fn is_palindrome(chars : String) -> Bool { let n = chars.length() - var i = 0 + let mut i = 0 while i < n / 2 { if chars[i] != chars[n - i - 1] { return false diff --git a/examples/path/lib/path.mbt b/examples/path/lib/path.mbt index 05caa42e..9400bdc5 100644 --- a/examples/path/lib/path.mbt +++ b/examples/path/lib/path.mbt @@ -25,8 +25,8 @@ pub fn parent(self : Path) -> String { match self.platform { Posix => { let (parts, l) = split(self.inner, '/') - var parent = "" - var index = 0 + let mut parent = "" + let mut index = 0 let end = if parts[l] == "" { l - 1 } else { @@ -40,8 +40,8 @@ pub fn parent(self : Path) -> String { } Windows => { let (parts, l) = split(self.inner, '\\') - var parent = "" - var index = 0 + let mut parent = "" + let mut index = 0 let end = if parts[l] == "" { l - 1 } else { diff --git a/examples/path/lib/string.mbt b/examples/path/lib/string.mbt index 99f62801..ffee71eb 100644 --- a/examples/path/lib/string.mbt +++ b/examples/path/lib/string.mbt @@ -1,7 +1,7 @@ pub fn split(s : String, sep : Char) -> (Array[String], Int) { - var index = 0 - var result : Array[String] = Array::make(5, "") - var cur = 0 + let mut index = 0 + let mut result : Array[String] = Array::make(5, "") + let mut cur = 0 let it = iter(s) while it.index != it.length { let c = match it.next() { @@ -17,7 +17,7 @@ pub fn split(s : String, sep : Char) -> (Array[String], Int) { cur = cur + 1 if cur >= result.length() { let new_result = Array::make(result.length() * 2, "") - var tmp_cur = 0 + let mut tmp_cur = 0 while tmp_cur < result.length() { new_result.set(tmp_cur, result[tmp_cur]) tmp_cur = tmp_cur + 1 @@ -40,7 +40,7 @@ pub fn sub_string(s : String, start : Int, end : Int) -> Option[String] { return None } let it = iter(s) - var result : String = "" + let mut result : String = "" while it.index != it.length { let c = match it.next() { Some(c) => c @@ -55,8 +55,8 @@ pub fn sub_string(s : String, start : Int, end : Int) -> Option[String] { pub fn trim(s : String, removed : Char) -> String { let l = s.length() - var start = 0 - var end = l - 1 + let mut start = 0 + let mut end = l - 1 while start < l && s[start] == removed { start = start + 1 } @@ -74,8 +74,8 @@ pub fn trim(s : String, removed : Char) -> String { pub fn index_of(s : String, pattern : String) -> Option[Int] { let prefix_func = prefix_function(pattern) - var s_index = 0 - var p_index = 0 + let mut s_index = 0 + let mut p_index = 0 let l = s.length() while s_index < l { if s[s_index] == pattern[p_index] { @@ -99,9 +99,9 @@ pub fn index_of(s : String, pattern : String) -> Option[Int] { pub fn last_index_of(s : String, pattern : String) -> Option[Int] { let prefix_func = prefix_function(pattern) - var s_index = 0 - var p_index = 0 - var index = -1 + let mut s_index = 0 + let mut p_index = 0 + let mut index = -1 let l = s.length() while s_index < l { if s[s_index] == pattern[p_index] { @@ -139,9 +139,9 @@ pub fn contains(s : String, sub : String) -> Bool { fn prefix_function(pattern : String) -> Array[Int] { let result = Array::make(pattern.length(), 0) let n = pattern.length() - var i = 1 + let mut i = 1 while i < n { - var j = result[i - 1] + let mut j = result[i - 1] while j > 0 && pattern[i] != pattern[j] { j = result[j - 1] } @@ -164,7 +164,7 @@ pub fn char_at(s : String, pos : Int) -> Option[Char] { pub fn to_char_array(s : String) -> Array[Char] { let l = s.length() let array = Array::make(l, ' ') - var index = 0 + let mut index = 0 while index < l { array[index] = s.get(index) index = index + 1 diff --git a/examples/string/lib/string.mbt b/examples/string/lib/string.mbt index d5d5dc2c..9a853c98 100644 --- a/examples/string/lib/string.mbt +++ b/examples/string/lib/string.mbt @@ -1,7 +1,7 @@ pub fn split(s : String, sep : Char) -> (Array[String], Int) { - var index = 0 - var result : Array[String] = Array::make(5, "") - var cur = 0 + let mut index = 0 + let mut result : Array[String] = Array::make(5, "") + let mut cur = 0 let it = iter(s) while it.index != it.length { let c = match it.next() { @@ -17,7 +17,7 @@ pub fn split(s : String, sep : Char) -> (Array[String], Int) { cur = cur + 1 if cur >= result.length() { let new_result = Array::make(result.length() * 2, "") - var tmp_cur = 0 + let mut tmp_cur = 0 while tmp_cur < result.length() { new_result.set(tmp_cur, result[tmp_cur]) tmp_cur = tmp_cur + 1 @@ -40,7 +40,7 @@ pub fn sub_string(s : String, start : Int, end : Int) -> Option[String] { return None } let it = iter(s) - var result : String = "" + let mut result : String = "" while it.index != it.length { let c = match it.next() { Some(c) => c @@ -55,8 +55,8 @@ pub fn sub_string(s : String, start : Int, end : Int) -> Option[String] { pub fn trim(s : String, removed : Char) -> String { let l = s.length() - var start = 0 - var end = l - 1 + let mut start = 0 + let mut end = l - 1 while start < l && s[start] == removed { start = start + 1 } @@ -74,8 +74,8 @@ pub fn trim(s : String, removed : Char) -> String { pub fn index_of(s : String, pattern : String) -> Option[Int] { let prefix_func = prefix_function(pattern) - var s_index = 0 - var p_index = 0 + let mut s_index = 0 + let mut p_index = 0 let l = s.length() while s_index < l { if s[s_index] == pattern[p_index] { @@ -99,9 +99,9 @@ pub fn index_of(s : String, pattern : String) -> Option[Int] { pub fn last_index_of(s : String, pattern : String) -> Option[Int] { let prefix_func = prefix_function(pattern) - var s_index = 0 - var p_index = 0 - var index = -1 + let mut s_index = 0 + let mut p_index = 0 + let mut index = -1 let l = s.length() while s_index < l { if s[s_index] == pattern[p_index] { @@ -139,9 +139,9 @@ pub fn contains(s : String, sub : String) -> Bool { fn prefix_function(pattern : String) -> Array[Int] { let result = Array::make(pattern.length(), 0) let n = pattern.length() - var i = 1 + let mut i = 1 while i < n { - var j = result[i - 1] + let mut j = result[i - 1] while j > 0 && pattern[i] != pattern[j] { j = result[j - 1] } @@ -164,7 +164,7 @@ pub fn char_at(s : String, pos : Int) -> Option[Char] { pub fn to_char_array(s : String) -> Array[Char] { let l = s.length() let array = Array::make(l, ' ') - var index = 0 + let mut index = 0 while index < l { array[index] = s.get(index) index = index + 1 diff --git a/examples/string/main/main.mbt b/examples/string/main/main.mbt index abd831f7..defc7ac3 100644 --- a/examples/string/main/main.mbt +++ b/examples/string/main/main.mbt @@ -1,6 +1,6 @@ fn init { let (arr, len) = @lib.split("a.b.c.e.f.g.h.i.j.k.l.m.n", '.') - var index = 0 + let mut index = 0 // let l = arr.length() while index < len { println(arr[index]) @@ -28,7 +28,7 @@ fn init { } let arr = @lib.to_char_array("HelloWorld") - var index = 0 + let mut index = 0 let l = arr.length() while index < l { println(arr[index]) diff --git a/examples/tetris/lib/draw.mbt b/examples/tetris/lib/draw.mbt index ab6bf0ed..6b950094 100644 --- a/examples/tetris/lib/draw.mbt +++ b/examples/tetris/lib/draw.mbt @@ -13,7 +13,7 @@ fn set_fill_style(self : Canvas_ctx, color : Int) = "canvas" "set_fill_style" fn draw_game_over(self : Canvas_ctx) = "canvas" "draw_game_over" pub fn draw(canvas : Canvas_ctx, tetris : Tetris) { - var c = 0 + let mut c = 0 // draw backgroud while c < grid_col_count { @@ -38,7 +38,7 @@ pub fn draw_piece(canvas : Canvas_ctx, matrix : List[Array[Int]], fn go(l : List[Array[Int]], r : Int, canvas : Canvas_ctx) { match l { Cons(v, n) => { - var c = 0 + let mut c = 0 while c < v.length() { if v[c] == 0 { c = c + 1 diff --git a/examples/tetris/lib/tetris.mbt b/examples/tetris/lib/tetris.mbt index 33fb3a7f..67e41d67 100644 --- a/examples/tetris/lib/tetris.mbt +++ b/examples/tetris/lib/tetris.mbt @@ -73,7 +73,7 @@ pub fn on_piece_collision(self : Tetris) { if r >= y + len_r { return } - var c = 0 + let mut c = 0 while c < len_c { if self.pice_shap[r - y][c] == 0 { c = c + 1 @@ -105,13 +105,13 @@ pub fn on_piece_collision(self : Tetris) { } } - var new_grid : List[Array[Int]] = Nil + let mut new_grid : List[Array[Int]] = Nil new_grid = go2(self.grid) // 1 line == 1 score self.score = self.score + self.row_completed // Insert blank row at the top - var i = 0 + let mut i = 0 while i < self.row_completed { new_grid = Cons(Array::make(grid_col_count, 0), new_grid) i = i + 1 @@ -143,7 +143,7 @@ pub fn drop_piece(self : Tetris, instant : Bool) { } pub fn move_piece(self : Tetris, delta : Int) { - var new_x = self.pice_x + delta + let mut new_x = self.pice_x + delta new_x = max(0, min(new_x, grid_col_count - self.pice_shap[0].length())) if check_collision(self.grid, self.pice_shap, (new_x, self.pice_y)) { return @@ -155,21 +155,21 @@ pub fn rotate_piece(self : Tetris) { let r = self.pice_shap.length() let c = self.pice_shap[0].length() let new_shap = Array::make(c, Array::make(r, 0)) - var i = 0 + let mut i = 0 while i < c { new_shap[i] = Array::make(r, 0) i = i + 1 } - var i_c = 0 + let mut i_c = 0 while i_c < c { - var i_r = 0 + let mut i_r = 0 while i_r < r { new_shap[i_c][i_r] = self.pice_shap[r - i_r - 1][i_c] i_r = i_r + 1 } i_c = i_c + 1 } - var new_x = self.pice_x + let mut new_x = self.pice_x if new_x + new_shap[0].length() > grid_col_count { new_x = grid_col_count - new_shap[0].length() } diff --git a/examples/tetris/lib/utils.mbt b/examples/tetris/lib/utils.mbt index 9c180f30..24531ff2 100644 --- a/examples/tetris/lib/utils.mbt +++ b/examples/tetris/lib/utils.mbt @@ -33,7 +33,7 @@ pub fn check_collision(grid : List[Array[Int]], shap : Array[Array[Int]], if r >= offset.1 + len_r { return false } - var c = 0 + let mut c = 0 while c < len_c { if shap[r - offset.1][c] == 0 { c = c + 1 @@ -70,7 +70,7 @@ pub fn min[T : Compare](a : T, b : T) -> T { } pub fn contain(ary : Array[Int], t : Int) -> Bool { - var i = 0 + let mut i = 0 while i < ary.length() { if ary[i] == t { return true @@ -83,7 +83,7 @@ pub fn contain(ary : Array[Int], t : Int) -> Bool { pub fn get_effective_height(grid : List[Array[Int]], shap : Array[Array[Int]], offset : (Int, Int)) -> Int { let x = offset.0 - var y = offset.1 + let mut y = offset.1 while check_collision(grid, shap, (x, y)) == false { y = y + 1 } diff --git a/zh-docs/README.md b/zh-docs/README.md index cc1b6a9f..c357d67c 100644 --- a/zh-docs/README.md +++ b/zh-docs/README.md @@ -197,8 +197,8 @@ while x == y { MoonBit 还提供 `break` 和 `continue` 语句来控制循环流。 ```rust -var i = 0 -var n = 0 +let mut i = 0 +let mut n = 0 while i < 10 { i = i + 1 @@ -218,7 +218,7 @@ println(n) // outputs 25 `while` 循环还可以有一个可选的 "continue" 块。"continue" 块位于循环条件和循环体之间,和循环条件用逗号分隔。它会在每次循环的循环体之后、下一次循环的循环条件之前被执行: ```rust -var i = 0 +let mut i = 0 while i < 10, i = i + 1 { println(i) } // outputs 0 to 9 @@ -227,7 +227,7 @@ while i < 10, i = i + 1 { 如果在一个 "continue" 块里有多个语句,它们需要被花括号包裹。循环体中的 `continue` 语句不会跳过 "continue" 块。例如,下面的例子会输出小于 10 的所有奇数: ```rust -var i = 1 +let mut i = 1 while i < 10, i = i + 1 { if (i % 2 == 0) { continue @@ -343,7 +343,7 @@ fn init { let zero = 0 fn init { - var i = 10 + let mut i = 10 i = 20 print(i + zero) }