Rust Program to Demonstrate the Nested For Loop

You are currently viewing Rust Program to Demonstrate the Nested For Loop

Here, We are going to discuss the topic of “Rust Program to Demonstrate the Nested For Loop“. Come on! Let’s move on to the topic directly.

Rust program to demonstrate the nested for loop

// Rust program to demonstrate the
// nested for loop

fn main() {
    let mut cnt1:i32 = 0;
    let mut cnt2:i32 = 0;
    
    for cnt1 in 2..6
    {
        for cnt2 in 1..11
        {
            print!("{} ",(cnt1*cnt2));
        }
        println!();
    }
}

Execution of Source Code

Here, The nested for loop is used to print the output of the tables between 2 and 6. The result will be displayed using the printIn() function.

Output

2 4 6 8 10 12 14 16 18 20 
3 6 9 12 15 18 21 24 27 30 
4 8 12 16 20 24 28 32 36 40 
5 10 15 20 25 30 35 40 45 50 

Final Words

That’s it, guys. I hope this article about “Rust Program to Demonstrate the Nested For Loop” will be very helpful to you. If you have any doubts please ask us through the comment section. Share this article with your friends to help them.

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply