Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Lesson 11 - Sub programs

E- LEARNING

Revise, Recap, Review

Objectives

3 commands used in SQL

2 examples of utility software

1 SQL statement to return all Jaguar 'make' cars from the table 'Cars'

Lesson Objectives

To know the difference between a function and a procedure

To know the advantages of using sub programs

To use sub programs to solve a problem

Sub programs

Theory

A mini program within your program

They SAVE TIME if we use repeated code in our program

Type the code out once and give it a name

When you want to use that block of code you just type the name

Other advantages

As well as saving time, sub programs:

+Make programs easier to edit once created

+Help debug errors

+Create a more logical structure to our code

Functions and procedures

Procedures are blocks of code stored under one name

Called by typing their name - sometimes we also pass an argument to them

With parameter

Functions

VERY similar, but functions ALWAYS return a value back to be used in the main program

Functions always take at least one parameter

When calling a function we assign it to a variable - otherwise the value returned is lost!

Functions

Local or Global?

Variables can be local or global

Any variable used within a sub program is local and can only be called within itself - if you try and print it in the main.....ERROR: NOT DEFINED!

This means you can use the same variable name as other local variables without any issues

Global

Global variables can be used anywhere in the program

We can declare a global variable using the global key word

This means that they are accessible from both the main body and the sub programs

Task

Task

Write a function takes two strings and joins them together with a space in between them.

Call your function and print out the result in the main program

Task

Plenary

What’s Next?

What’s Next

Your Project!

Next Lesson

Learn more about creating dynamic, engaging presentations with Prezi