Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound...

14
Computer Science Computer Science By: Erica Ligons

Transcript of Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound...

Page 1: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Computer ScienceComputer Science

By: Erica Ligons

Page 2: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

CompoundCompound StatementStatement

A compound statement-A compound statement- is a unit of code consisting of zero or more statement also known as a blockblock

Page 3: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Model Of StatementModel Of StatementExpression Statement

Compound Statement

Selection Statement

Labeled Statement

Iterative Statement

Jump Statement

Statement

Page 4: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Purpose of the Purpose of the Compound StatementCompound Statement

1. The compound statement allows it user to make groups of statements into a single chunk

2. Parts of Compound StatementOpening Brace

Closing Brace

Page 5: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

FunctionsFunctions

Function-Function- a subroutine The “C” Program consist of many

functions, however, only one of the functions can be called a main

The main has the ability to allocate special tasks

The purpose of the function is to be able to receive one or more pieces of data

Page 6: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Side Effects of Side Effects of FunctionsFunctions

Side effects- occurs when the is a Side effects- occurs when the is a change in the state of the programchange in the state of the program

Aspects of a Side EffectAspects of a Side Effect1.1. Accepting data from outside sourceAccepting data from outside source

2.2. Sending data to monitor or fileSending data to monitor or file

3.3. Changing the value of a variableChanging the value of a variable

Page 7: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Function DeclarationFunction Declaration

Function declaration-Function declaration- is done with a prototype declaration

Purposes For Calling A Functions Name1. When a function is declared

2. When it is called

3. When it is defined

Page 8: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Function CallFunction Call

Function call- is used for the purpose of calling a function

Actual parameters-represent the values tat are to be sent to the called function

Page 9: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Parameter PassingParameter Passing

Can pass parameter in two ways:Pass by valuePass by value- a copy of the data is created

and placed in a local variable in the called function

Pass by reference-Pass by reference- sends the address of a viable to the called function

Page 10: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Function DefinitionFunction Definition

Function definition-Function definition- contains the code for for functions. It has two parts the header and function of the body.Function Header Parts

1.The return type2. The function name3. Compound statement

Function body-Function body- contains declarations and statements for the functions

Page 11: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Selection Selection

If else-If else- use for two-way selectionsSwitch Selection-Switch Selection- does the same as if else

Page 12: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

LoopsLoops

There are three types of loopsWhile loop- checks the value of a testing

expression, pretestFor loop- it is a counter-control loop, pretestDo-while loop- event controlled loop, but it

is a posttest loop

Page 13: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.
Page 14: Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.

Expression Statement

Compound Statement

Selection Statement

Labeled Statement

Iterative Statement

Jump Statement

Statement