Skip to content

Commit 6e47f1a

Browse files
committed
Added intro for advanced loops
1 parent b281941 commit 6e47f1a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

CH40208/python_basics/advanced_loop_control.ipynb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
"source": [
88
"# Advanced Loop Control\n",
99
"\n",
10+
"In the [Loops](loops.ipynb) section, you learnt how to use `for` loops to iterate over sequences. In the [Comparisons and Flow Control](comparisons_and_flow_control.ipynb) section, you learnt how to use `if` statements to make decisions in your code. Now we'll combine these concepts and introduce some more advanced loop control structures.\n",
11+
"\n",
12+
"This section covers:\n",
13+
"- **`while` loops**: loops that continue until a condition is no longer true\n",
14+
"- **`break`**: exiting a loop early\n",
15+
"- **`continue`**: skipping to the next iteration of a loop\n",
16+
"\n",
17+
"These tools are particularly useful in computational chemistry for iterative algorithms that need to run until convergence, or for processing datasets where you need to skip invalid data or stop when certain conditions are met.\n",
18+
"\n",
19+
"**Prerequisites:** Before working through this section, make sure you're comfortable with:\n",
20+
"- Basic `for` loops and `range()` (from [Loops](loops.ipynb))\n",
21+
"- `if`/`elif`/`else` statements (from [Comparisons and Flow Control](comparisons_and_flow_control.ipynb))\n",
22+
"- Comparison operators (`<`, `>`, `==`, etc.)\n",
23+
"\n",
1024
"## `while` loops\n",
1125
"\n",
1226
"In addition to `for` loops, Python also provides `while` loops for situations where you want to repeat a block of code as long as a condition is true.\n",

0 commit comments

Comments
 (0)