Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,950 questions

51,892 answers

573 users

How to print an array using for loop in Rust

3 Answers

0 votes
fn main() {
    let arr:[i32; 6] = [3, 19, 21, 0, 189, 7];
    
    for index in 0..6 {
        println!("index: {} & value: {}",index, arr[index]);
    }
}






/*
run:

index: 0 & value: 3
index: 1 & value: 19
index: 2 & value: 21
index: 3 & value: 0
index: 4 & value: 189
index: 5 & value: 7

*/

 



answered Oct 25, 2022 by avibootz
0 votes
fn main() {
    let arr:[i32; 6] = [150, 19, 21, 0, 189, 99];
    
    for index in 0..arr.len() {
        println!("index: {} & value: {}",index, arr[index]);
    }
}






/*
run:

index: 0 & value: 150
index: 1 & value: 19
index: 2 & value: 21
index: 3 & value: 0
index: 4 & value: 189
index: 5 & value: 99

*/

 



answered Oct 25, 2022 by avibootz
0 votes
fn main() {
    let arr:[i32; 6] = [150, 19, 21, 0, 189, 99];
    
    for val in arr.iter() {
        println!("{}", val);
    }
}






/*
run:

150
19
21
0
189
99

*/

 



answered Oct 25, 2022 by avibootz

Related questions

1 answer 144 views
1 answer 132 views
1 answer 146 views
1 answer 128 views
1 answer 97 views
2 answers 135 views
...