Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 779 Bytes

File metadata and controls

33 lines (25 loc) · 779 Bytes

for statement

Syntax
ForStatement :
   for IDENTIFIER in Expression {
   (Statement | Expression)+
   }

A for statement is a syntactic construct for looping over elements provided by an array type.

An example of a for loop over the contents of an array:

Example:

contract Foo {

    pub fn bar(values: Array<u256, 10>) -> u256 {
        let mut sum: u256 = 0
        for i in values {
            sum = sum + i
        }
        return sum
    }
}