{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "total = 0\n",
    "for i in range(1, 5):\n",
    "    total += i\n",
    "print(total)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "total2 = 0\n",
    "j = 1\n",
    "while j < 5:\n",
    "    total2 += j\n",
    "    j += 1\n",
    "print(total2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17\n"
     ]
    }
   ],
   "source": [
    "given_list = [5, 4, 4, 3, 1]\n",
    "\n",
    "total3 = 0\n",
    "i = 0\n",
    "while i < len(given_list) and given_list[i] > 0:\n",
    "    total3 += given_list[i]\n",
    "    i += 1\n",
    "print(total3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17\n"
     ]
    }
   ],
   "source": [
    "given_list2 = [5, 4, 4, 3, 1, -2, -3, -5]\n",
    "total4 = 0\n",
    "for element in given_list2:\n",
    "    if element <= 0:\n",
    "        break\n",
    "    total4 += element\n",
    "print(total4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17\n"
     ]
    }
   ],
   "source": [
    "# given_list2 = [5, 4, 4, 3, 1, -2, -3, -5]\n",
    "total5 = 0\n",
    "i = 0\n",
    "while True:\n",
    "    total5 += given_list2[i]\n",
    "    i += 1\n",
    "    if given_list2[i] <= 0:\n",
    "        break\n",
    "print(total5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "given_list3 = [7, 5, 4, 4, 3, 1, -2, -3, -5, -7]\n",
    "\n",
    "# csdojo.io/python6\n",
    "# follow CS Dojo on Facebook"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
