January 2018
Beginner to intermediate
454 pages
10h 8m
English
There are multiple kinds of loop in Rust. One of them is the while loop.
Let's see how to compute the greatest common divisor 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 divisor of 15 and 40 is: {}", a);
This code executes successive divisions and stops doing so when the remainder is 0.
Read now
Unlock full access