start
start(iter) -> state
Get initial iteration state for an iterable object
Examples
Example 1: Get initial state for an array:
julia> arr = [1, 2, 3, 4, 5];
julia> start(arr)
1
In this example, the start
function returns the initial state of the array arr
, which is the first element of the array.
Example 2: Get initial state for a range object:
julia> rng = 1:5;
julia> start(rng)
1
The start
function returns the initial state of the range object rng
, which is the first element of the range.
Example 3: Get initial state for a string:
julia> str = "Hello";
julia> start(str)
'H': ASCII/Unicode U+0048 (category Lu: Letter, uppercase)
Here, the start
function returns the initial state of the string str
, which is the first character of the string.
Common mistake example:
julia> num = 10;
julia> start(num)
ERROR: MethodError: no method matching start(::Int64)
This example shows a common mistake where the start
function is used on a non-iterable object. The start
function can only be applied to iterable objects like arrays, ranges, strings, etc. It cannot be used on a single number or non-iterable data types.
See Also
countfrom, cycle, done, drop, eachindex, enumerate, first, repeated, rest, start, svds, take, vecdot, vecnorm, zip,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.