Event CS Thinking Example 2

Follow the full solution, then compare it with the other examples linked below.

Example 2

medium
Compare event-driven programming with sequential programming. Give an example of each.

Solution

  1. 1
    Step 1: Sequential: the program runs instructions in order from start to finish. Example: a script that reads a file, processes it, and outputs results.
  2. 2
    Step 2: Event-driven: the program waits for events and responds to them as they occur. Example: a web page that responds to button clicks, mouse movements, and keyboard input.
  3. 3
    Step 3: Most modern applications (apps, games, web pages) use event-driven programming because they need to respond to unpredictable user actions.

Answer

Sequential runs instructions in order. Event-driven waits and responds to events. Most interactive applications use event-driven programming.
Event-driven programming is essential for interactive applications. The program does not control the order of operations — the user does, through events.

About Event

A detectable action or occurrence in a program—such as a user click, key press, mouse movement, or timer expiry—that the program can respond to by executing a predefined event handler function.

Learn more about Event →

More Event Examples