You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suggestion: Use this for_ macro instead of manual while loops to make the intention clearer:
pub macro for_($start:expr, $end:expr, $(step: $step:expr,)? $($label:lifetime:)? |$var:pat| $body:block){{let _step = iffalse{ $start }else{1as_};// type inference for default step
$(
let _step = $step;// custom step)?
letmut i = $start;
$($label:)? while i < $end {let $var = i;
i += _step;// before body, to make `continue` work
$body;}}}
I think it makes the purpose clearer (no need to declare an extra variable just for looping), it makes looping "automatic" (no need to remember to put i += 1; at the end) and reduces the number of mutable vars, thus making it easier to reason about the code / makes the purpose clearer.
The text was updated successfully, but these errors were encountered:
Suggestion: Use this
for_
macro instead of manual while loops to make the intention clearer:You can use it like:
It also works for floats and supports a custom
step
and label arg, e.g.:I think it makes the purpose clearer (no need to declare an extra variable just for looping), it makes looping "automatic" (no need to remember to put
i += 1;
at the end) and reduces the number of mutable vars, thus making it easier to reason about the code / makes the purpose clearer.The text was updated successfully, but these errors were encountered: