Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 129
Image: ubuntu2004
Kernel: Python 3 (system-wide)

This is an algorithm that sums the values 1, 2, 3, 4, 5 in two ways: using the for loop and using the while loop.

First, we use the for loop method:

n=0 for i in range(1,6): n=n+i print(n)
15

Here's a way using the while loop:

n=0 sum=0 while n<6: sum=sum+n n=n+1 print(sum)
15