Basics of Programming and Flow Control

Sep 19, 2024

Lecture Notes: Introduction to Programming and Flow Control

Key Concepts

  • Humans vs Computers
    • Humans are smarter than computers.
    • Programmers write instructions (code) for computers to follow.

What is Code?

  • Code: A language that computers understand.
  • Purpose of code: To make a program run or work.
  • Example applications of code:
    • Moving a character across a screen
    • Entire games

Flow Control Structures

  • There are three basic flow control structures:
    1. Sequence
    2. Selection
    3. Iteration

Focus: Sequence

  • Definition of Sequence:
    • An order of events.
    • Everything we do can be broken into a series of steps (algorithm).

Algorithm Explained

  • An algorithm is the order of events followed to complete a task.
  • Example: Washing hands
    1. Get hands wet
    2. Get soap
    3. Wash off soap
    4. Dry hands

Importance of Specific Instructions

  • Humans can follow general steps, but computers need detailed instructions.
  • Example questions for a computer:
    • How to move towards the sink?
    • How to turn the water on?
    • How long to rub hands together?

Bugs in Programming

  • Definition of a Bug:
    • An error in the code that prevents proper functioning.
  • Effects of Bugs:
    • Programs can crash, freeze, or malfunction.

Debugging

  • Debugging: The process of finding and fixing mistakes in code.
  • Similar to correcting errors in writing or math.

Practice Activity

  • Task: Put commands in the correct sequence to instruct a character (fuzz) through a maze.
  • Reminder: If there's a bug, try again!