Pure Programmer
Blue Matrix


Cluster Map

Iteration

L1

This page is under construction. Please come back later.

Iteration1.rs
mod utils;
use std::env;

fn main() {
	let args: Vec<String> = env::args().collect();
	let mut max:isize = 5;
	if args.len() == 2 {
		max = Utils.stoiWithDefault(args[1], 5);
	}
	{
		let mut i_:isize = 0;
		while i_ < max {
			println!("Hello, world!");
			i_ += 1;
		}
	}
}

Output
$ rustc Iteration1.rs error[E0425]: cannot find value `Utils` in this scope --> Iteration1.rs:8:9 | 8 | max = Utils.stoiWithDefault(args[1], 5); | ^^^^^ not found in this scope error: aborting due to previous error For more information about this error, try `rustc --explain E0425`.
Iteration2.rs
fn main() {
	{
		let mut i:isize = 10;
		while i >= 1 {
			println!("{}", i);
			i += -1;
		}
	}
	println!("Blastoff!");
}

Output
$ rustc Iteration2.rs $ ./Iteration2 10 9 8 7 6 5 4 3 2 1 Blastoff!
Iteration3.rs
fn main() {
	println!("Even numbers up to 100...");
	{
		let mut i:isize = 2;
		while i <= 100 {
			println!("{}", i);
			i += 2;
		}
	}
}

Output
$ rustc Iteration3.rs $ ./Iteration3 Even numbers up to 100... 2 4 6 8 10 12 14 16 18 ... 82 84 86 88 90 92 94 96 98 100
Iteration4.rs
fn main() {
	println!("Floating point numbers");
	{
		let mut d:f64 = 1.0f64;
		while d < 2.01f64 {
			println!("{}", d);
			d += 0.1f64;
		}
	}
}

Output
$ rustc Iteration4.rs $ ./Iteration4 Floating point numbers 1 1.1 1.2000000000000002 1.3000000000000003 1.4000000000000004 1.5000000000000004 1.6000000000000005 1.7000000000000006 1.8000000000000007 1.9000000000000008 2.000000000000001
Iteration5.rs
fn main() {
	println!("Powers of 2 up to 256!");
	{
		let mut i:isize = 1;
		while i <= 256 {
			println!("{}", i);
			i *= 2;
		}
	}
}

Output
$ rustc Iteration5.rs $ ./Iteration5 Powers of 2 up to 256! 1 2 4 8 16 32 64 128 256
Iteration6.rs
fn main() {
	let mut s:&str = "Hello, world! 🥰🇺🇸";
	for c in s.chars() {
		println!("{}", c);
	}
}

Output
$ rustc Iteration6.rs warning: variable does not need to be mutable --> Iteration6.rs:2:6 | 2 | let mut s:&str = "Hello, world! 🥰🇺🇸"; | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default warning: 1 warning emitted $ ./Iteration6 H e l l o , w o r l d ! 🥰 🇺 🇸

Iterators

Questions

Projects

More ★'s indicate higher difficulty level.

References