Constructs - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Constructs

Description:

Programming Style. Leave Plenty of White Space. Each Statement on a Separate Line ... Note: return is usually used to return an error code. Use break; ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 11
Provided by: AFG4
Category:
Tags: constructs | style

less

Transcript and Presenter's Notes

Title: Constructs


1
Constructs
  • Control Statements / Constructs
  • Provide Control in Your Program
  • Syntax - Structure of Construct
  • if, while, do - while, for,
    switch

2
if , if-else
  • if (expression) expression in
    parenthesis
  • statement 1
  • statement 2 block
  • else
  • statement 1
  • statement 2 block

3
if
  • If Only One Statement in Block...
  • if (expression)
  • statement

4
while
  • while (expression)
  • statement1
  • statement2
  • increment counter if necessary

5
do - while
  • do
  • statement 1
  • statement 2
  • increment counter if necessary
  • while (expression)

6
for
  • for ( counter init comparison counter
    increment)
  • statement 1
  • statement 2
  • NO NEED to increment counter inside loop

7
switch
  • switch (expression) usually a variable
  • case value statement1
  • break
  • case value statement2
  • break
  • default statement 3
  • break
  • Executes from Hit down if you dont include
    breaks for each case!

8
Programming Style
  • Leave Plenty of White Space
  • Each Statement on a Separate Line
  • Lots of Indentation
  • Dont Stack Function Calls into Relational and
    Logical Evaluations Unless Absolutely Necessary
  • Use Hungarian Notation for Naming Variables

9
Exit Logic
  • Use return(variable)
  • when returning a value to the calling function
  • Note return is usually used to return an error
    code
  • Use break
  • to break out of a loop or switch
  • Use continue
  • to skip the remaining lines in a loop and start
    over
  • Use exit( 0 ) to exit the program with no
    error
  • Use exit( 1 ) to exit the program with
    error

10
  • switch ( lecture )
  • case done 15 Minute
  • break
  • exit ( LAB )
Write a Comment
User Comments (0)
About PowerShow.com