What is control flow?


In the context of this exercise, what is control flow?


Control flow is the concept of how a sequence of steps in a program flows, or runs from start to finish. The flow of a program can be dependent on factors such as the results of conditional statements, which utilize if/else if/else statements.

For example, we might have a Python program that prints out some message depending on the input value of the user. It will first run the try block code, and if the user input is not valid (not a numerical value) and brings up an error, then it will run the except block instead.

  age = int(raw_input("Enter your age:"))
  if age < 18:
    print("You must be 18 or over to enter the race")
    print("You can enter the race")
  print("The inputted age was invalid")

When an instruction has been executed, control is handed to the next instruction. Flow describes which branch is followed from a conditional.


A post was split to a new topic: What was the main reason of using Python for this course

A post was split to a new topic: Can copy but I can’t paste