Control Flow

3. Control Flow#

This chapter covers the topics:

  • Introduction to Control Structures

  • Conditional Statements (if, elif, else)

  • Loops (for, while)

  • Control Flow Keywords (break, continue, pass)

Control structures sequence selection and iteration

Fig. 3.1 Control structures sequence selection and iteration #

Control Flow Statements Type

Control Flow Statement

Description

Conditional Statements

if-else

Executes a block of code if a specified condition is true, and another block if the condition is false.

switch-case

Evaluates a variable or expression and executes code based on matching cases.

Looping Statements

for

Executes a block of code a specified number of times, typically iterating over a range of values.

while

Executes a block of code as long as a specified condition is true.

do-while (while True in Python)

Executes a block of code once and then repeats the execution as long as a specified condition is true.

Jump Statements

break

Terminates the loop or switch statement and transfers control to the statement immediately following the loop or switch.

continue

Skips the current iteration of a loop and continues with the next iteration.

return

Exits a function and returns a value to the caller.

goto

Transfers control to a labeled statement within the same function. (Note: goto is generally discouraged due to its potential for creating unreadable and error-prone code.)

source: geeksforgeeks

Is an inner function the same as goto?

No. goto is one way to