Skip to content

Instantly share code, notes, and snippets.

@takurx
Last active October 9, 2022 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takurx/6034ef1fca035fcc81825dd3fbf298ef to your computer and use it in GitHub Desktop.
Save takurx/6034ef1fca035fcc81825dd3fbf298ef to your computer and use it in GitHub Desktop.
test string Rust language

log

chiya@ujimatsu:~/Works/hello_rust/hello_rust_string$ cargo run
   Compiling hello_rust v0.1.0 (/home/chiya/Works/hello_rust/hello_rust_string)
    Finished dev [unoptimized + debuginfo] target(s) in 0.36s
     Running `target/debug/hello_rust`
Hello, world! 1
    odd number
Hello, world! 2
    even number
Hello, world! 3
    odd number
Hello, world! 4
    even number
H
e
l
l
o

code

fn main() {
    let str_hello = "Hello";
    let str_world = "world!";
    let str_hello_world = String::from(str_hello) + ", " + str_world;
    let str_even = "even number";
    let str_odd = "odd number";
    for n in 1..5 {
        println!("{} {}", str_hello_world, n);
        if n%2 == 0 {
            println!("    {}", str_even);
        }
        else {
            println!("    {}", str_odd);
        }
    }
    for i in str_hello.chars() {
        println!("{}", i);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment