From the course: Complete Guide to Advanced SQL Server
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Create a Python while loop - SQL Server Tutorial
From the course: Complete Guide to Advanced SQL Server
Create a Python while loop
There are two forms of looping statements that you can write with Python, and these are useful for executing the same tasks repeatedly. They're known as while loops and for loops. Let's take a look at each one. The while loop is used when you want to execute a block of code, as long as a condition remains true. I'm going to start by creating a variable called A, and I'm going to set its initial value to one. Then we'll start the while loop and say that while A is less than 10, and this sets up the condition. So as long as the value of A is less than 10, then the following lines will execute. We move into the loop block with a colon and then indent the next lines two spaces. So as long as A is less than 10, I want to print the current value of A to the Messages window. Then I want to increase the value of A by one. We can do that on the next slide by typing in A is equal to A plus one. And that's all there is to the while loop. Python doesn't use the same BEGIN and END statements that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.