官术网_书友最值得收藏!

  • Rust Programming By Example
  • Guillaume Gomez Antoni Boucher
  • 83字
  • 2021-07-02 19:12:57

Creating while loops

There are multiple kinds of loop in Rust. One of them is the while loop.

Let's see how to compute the greatest common pisor using the Euclidean algorithm:

let mut a = 15;
let mut b = 40;
while b != 0 {
    let temp = b;
    b = a % b;
    a = temp;
}
println!("Greatest common pisor of 15 and 40 is: {}", a);

This code executes successive pisions and stops doing so when the remainder is 0.

主站蜘蛛池模板: 涿州市| 肥乡县| 永登县| 乐东| 锡林浩特市| 民和| 万安县| 辛集市| 萨嘎县| 桂东县| 平遥县| 安龙县| 登封市| 琼中| 得荣县| 哈尔滨市| 昆明市| 信丰县| 富平县| 肇东市| 兰考县| 鹤壁市| 罗定市| 金堂县| 新晃| 依兰县| 兴国县| 华阴市| 缙云县| 湘潭市| 多伦县| 方正县| 合作市| 怀来县| 读书| 大邑县| 仙游县| 正阳县| 泸溪县| 罗山县| 大余县|