Skip to content

Add example for uint::range_step. #6841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/libstd/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,18 @@ pub fn ge(x: $T, y: $T) -> bool { x >= y }
pub fn gt(x: $T, y: $T) -> bool { x > y }

#[inline(always)]
///
/// Iterate over the range [`start`,`start`+`step`..`stop`)
///
/**
* Iterate through a range with a given step value.
*
* # Examples
* ~~~ {.rust}
* let nums = [1,2,3,4,5,6,7];
*
* for uint::range_step(0, nums.len() - 1, 2) |i| {
* println(fmt!("%d & %d", nums[i], nums[i+1]));
* }
* ~~~
*/
pub fn range_step(start: $T, stop: $T, step: $T_SIGNED, it: &fn($T) -> bool) -> bool {
let mut i = start;
if step == 0 {
Expand Down