版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wowotuo/article/details/85016778
方案一:for
use std::io::{self, Write};
use std::{thread, time};
fn main() {
let sleep_seconds = time::Duration::from_secs(1000);
for k in 1..20 {
print!("@");
for _ in 1..=k {
print!("*");
}
}
io::stdout().flush().unwrap();
thread::sleep(sleep_seconds);
}
方案二:for_each
use std::io::{self, Write};
use std::{thread, time};
fn main() {
let sleep_seconds = time::Duration::from_secs(1000);
(1..20).for_each(|k| {
print!("@");
(1..=k).for_each(|_| print!("*"))
});
io::stdout().flush().unwrap();
thread::sleep(sleep_seconds);
}
output: