Counting

Description

In Sage, you count by iterating over a range of integers. Notice the indentation of the second line.

Sage Cell

Code

for i in range(3):
print(i)
[[/code]]

Options

The third argument in a for loop controls the step size.

Code

for i in range(1,6,2):
    print(i)

Tags

Primary Tags: Programming: The Python language.

Secondary Tags: The Python language: Control flow statements.

Related Cells

Iteration, Tables, and String Formatting

Attribute

Permalink:

Author: Sage Tutorial v7.6

Date: 07 Jul 2017 15:16

Submitted by: Tom Judson

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License