Last active
September 25, 2016 01:56
-
-
Save dumindu/839e4f2c021679fc9e17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loop { | |
println!("Loop forever!"); | |
} | |
// Usage of break and continue | |
let mut a = 0; | |
loop { | |
if a == 0 { | |
println!("Skip Value : {}", a); | |
a += 1; | |
continue; | |
} else if a == 2 { | |
println!("Break At : {}", a); | |
break; | |
} | |
println!("Current Value : {}", a); | |
a += 1; | |
} | |
// Outer break | |
let mut b1 = 1; | |
'outer_loop: loop { //set label outer_loop | |
let mut b2 = 1; | |
'inner_loop: loop { | |
println!("Current Value : [{}][{}]", b1, b2); | |
if b1 == 2 && b2 == 2 { | |
break 'outer_loop; // kill outer_loop | |
} else if b2 == 5 { | |
break; | |
} | |
b2 += 1; | |
} | |
b1 += 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment