Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
error: expected `for` closure to return `bool`, but found `bool`
fn limited_while(nmax: uint, condition: &fn() -> bool, body: &fn() -> bool) {
for nmax.times {
if (!(condition() && body())) {
break
}
}
}
macro_rules! limited_while(
($condition: expr, nmax: $nmax: expr) => (
|body| {limited_while($nmax, || $condition, body); true}
);
)
fn main() {
let mut answer = ~"";
for (limited_while!(answer != ~"42", nmax: 3)) {
io::println("What’s the answer to [etc.]?");
answer = io::stdin().read_line();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.