Aryan PrajapatKnowledge Contributor
Is there a way to continue an outer loop from an inner loop in Rust?
Is there a way to continue an outer loop from an inner loop in Rust?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
Yes, Rust support continuing an outer loop when executing an inner loop through the use of loop labels:
let mut a = 0;
‘outer: loop {
a += 1;
let mut b = 0;
loop {
if b == 3 {
continue ‘outer;
}
b += 1;
}
}
Using loop labels with the break keyword instead of continue will enable an inner loop to exit both an inner and outer loop.