ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the nested for loop

Rust | Nested for Loop Example: Using the nested for loop, we have to print the tables from 2 to 5.
Submitted by Nidhi, on October 05, 2021

Problem Solution:

In this program, we will use a nested for loop to print tables from 2 to 5.

Program/Source Code:

The source code to demonstrate the nested for loop is given below. The given program is compiled and executed successfully.

// 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!();
    }
}

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 

Explanation:

Here, we used a nested for loop to print tables from 2 to 5.

Rust Looping Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.