Category: Conditionals and Loops

pass Statement

pass Statement

One Python statement not found in C is the pass statement. Because Python does not use curly braces to delimit blocks of code, there are places where code is syntactically required. We do not...

continue Statement

continue Statement

Whether in Python, C, Java, or any other structured language which features the continue statement, there is a misconception among some beginning programmers that the traditional continue statement “immediately starts the next iteration of...

break Statement

break Statement

The break statement in Python terminates the current loop and resumes execution at the next statement, just like the traditional break found in C. The most common use for break is when some external...

range() function

range() function

The built-in function range() can turn your foreach-like for-loop back into one that you are more familiar with, i.e., counting from zero to ten, or counting from 10 to 100 in increments of 5....

Switch/Case Statement Proxy

Switch/Case Statement Proxy

Earlier in previous programs, we introduced the if-elif-else construct and indicated that Python did not support a switch/case statement. In many cases, an incredibly long set of if-elif-else statements can be replaced by a...

for Statement

for Statement

The other looping mechanism in Python comes to us in the form of the for statement. Unlike the traditional conditional looping for statement found in mainstream third generation languages (3GLs) like C, Fortran, or...

Infinite Loops

Infinite Loops

One must use caution when using while loops because of the possibility that this condition never resolves to a false value. In such cases, we would have a loop that never ends on our...

while Statement

while Statement

Python’s while is the first looping statement. In fact, it is a conditional looping statement. In comparison with an if statement where a true expression will result in a single execution of the if...

if else Statement

if else Statement

Like other languages, Python features an else statement that can be paired with an if statement. The else statement identifies a block of code to be executed if the conditional expression of the if...