fundamentalsofprogrammingfinal 121011003536-phpapp02

46
FUNDAMENTALS OF PROGRAMMING Switch Case and Looping Statement http://eglobiotraining. com/ By:Kristine Sonsing

Upload: thinesonsing

Post on 09-Dec-2014

352 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Fundamentalsofprogrammingfinal 121011003536-phpapp02

FUNDAMENTALS OF PROGRAMMING

•Switch Case and •Looping Statement

http://eglobiotraining.com/

By:Kristine Sonsing

Page 2: Fundamentalsofprogrammingfinal 121011003536-phpapp02

TABLE OF CONTENTS

The If – else Statement If statement (two alternatives)If statement (One-Alternatives)How to save and run your statement Five Programs that is related on switch case programOutput

http://eglobiotraining.com/

•Programming

•Switch Case

•Looping Statement The while Loop The Do… While Loop The For Loop The Foreach Loop Break and continue statement Output

Page 3: Fundamentalsofprogrammingfinal 121011003536-phpapp02

SWITCH CASE

http://eglobiotraining.com/

Page 4: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

We first define the word “programming”, it is a computer language programmers use to develop applications, scripts, or other set of instructions for a computer to execute. 

programming is instructing a computer to do something for you with the help of a programming language. The role of a programming language can be described in two ways:Technical: It is a means for instructing a Computer to perform TasksConceptual: It is a framework within which we organize our ideas about things and processes.

Programming

Page 5: Fundamentalsofprogrammingfinal 121011003536-phpapp02

As an individual, I have learned that programming is a very broad because it composes many scripts, applications and can be used to run a program that has been part of the programming language.

A programming language should both provide means to describe primitive data and procedures and means to combine and abstract those into more complex ones.

http://eglobiotraining.com/

Page 6: Fundamentalsofprogrammingfinal 121011003536-phpapp02

The distinction between data and procedures is not that clear cut. In many programming languages, procedures can be passed as data (to be applied to ``real'' data) and sometimes processed like ``ordinary'' data. Conversely ``ordinary'' data can be turned into procedures by an evaluation mechanism.

http://eglobiotraining.com/

Page 7: Fundamentalsofprogrammingfinal 121011003536-phpapp02

If we know how to write a C expression that is equivalent of a question such as “Is resting the value of expression to select a course of action. In C, the statement is the primary selection control structure

Me: it’s hard to write c expression. So, I just copy and paste it into internet.

A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.

http://eglobiotraining.com/

Page 8: Fundamentalsofprogrammingfinal 121011003536-phpapp02

At first, programming is confusing because you have so much to understand about codes that will enable to run a program. Programming has applications and program development, the best example for this is the Internet browser…

Programming is a creative process done by programmers to instruct a computer on how to do a task. Programming languages let you use them in different ways, e.g adding numbers, etc… or storing data on disk for later retrieval.

http://eglobiotraining.com/

Page 9: Fundamentalsofprogrammingfinal 121011003536-phpapp02

You have to consider languages to run or write your own program, most demanded language in programming is the DEV C++ (a full-featured Integrated Development Environment (IDE)).

C++ is one of the most used programming languages in the world. Also known as "C with Classes". 

New to programming or thinking about it? It might surprise you to know that there are many programmers who program just for fun and it can lead to a job.

http://eglobiotraining.com/

Page 10: Fundamentalsofprogrammingfinal 121011003536-phpapp02

SWITCH CASE

http://eglobiotraining.com/

- A switch, case, select or inspect statement is a type of selection control mechanism that exists in most imperative programming languages such as Pascal, Ada, C/C++, C#, Java, and so on. It is also included in several other types of languages. Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multiway branch (or "goto", one of several labels). 

The Main Reason using switch case : - To improve clarity, by reducing otherwise repetitive coding, and (if the heuristics permit) also offering the potential for faster execution through easier compiler optimization in many cases.

Page 11: Fundamentalsofprogrammingfinal 121011003536-phpapp02

PROGRAMS THAT IS RELATED TO SWITCH CASE

http://eglobiotraining.com/

1. The If – else Statement

-The if statement allows the programmer to make decisions within a program.

- The general format of an if statement is:

If (expression) statement

-Where expression represents a relational, equality, orlogical expression ( conditional expression) .

Page 12: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

If statement (One-Alternatives)

If (condition) statement;

Form:

Note: if condition evaluates to true, then statement is executed and statement is skipped

If statement (two alternatives)

Form:If (condition) statement;else statement;

Note: if condition evaluates to true, then statement is executed and statement is skipped; otherwise, statement is skipped and statement is executed

Format of the if statement

- All if statement examples in this text indent statements. The word elseIs typed without indention on a separate line. The format of the if statement makes its meaning apparent and is used solely to improve program readability; The format makes no difference to the computer

Page 13: Fundamentalsofprogrammingfinal 121011003536-phpapp02

There may be a situation when you need to execute a block of code several number of times. In general statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.

Programming languages provide various control structures that allow for more complicated execution paths.

A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages:

http://eglobiotraining.com/

Page 14: Fundamentalsofprogrammingfinal 121011003536-phpapp02

HOW TO SAVE AND RUN YOUR STATEMENTS? 1. Open Dev C++ 2. Click File and choose New 3. Post your Statements 4. after you post your statement 5. Save it .choose file and save or 6. click f9 or you can see it shaped like a square

http://eglobiotraining.com/

Page 15: Fundamentalsofprogrammingfinal 121011003536-phpapp02

FIVE PROGRAMS THAT IS RELATED ON SWITCH CASE STATEMENT

http://eglobiotraining.com/

Page 16: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://gd.tuwien.ac.at/languages/c/programming-bbrown/c_028.htm

Link:

The above program uses a switch statement to validate and select upon the users input choice, simulating a simple menu of choices.

Page 17: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

When it compiles and run, this will be it look . The C expression that was type it on Dev C++ The words are “enter in two number 24”

Page 18: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://www.morrowland.com/apron/tutorials/cpp/cpp_switch_case/index.php

Link:

Example of Switch Case Statement , you Will see the statement on the link that you see in this slide.

Page 19: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

After I compile it and run it, the statement is now like this. As you Can see after you answer the 1st question the next question appear And after you finish all the question the box will disappear. It means finish.

Page 20: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://www.morrowland.com/apron/tutorials/cpp/cpp_if_else/index.php

Link:

Function and target of Programming language :

A computer programming language is a language. used to write computer programs,

which involve a computer performing some

kind of computation or algorithm and

possibly control external devices such as printers , disk

drives , robots, and so on.

Page 21: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

When the statement was done this will it be look like. I got this from the URL . The URL was posted on the

previous slide

Page 22: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://msdn.microsoft.com/en-us/library/66k51h7a(v=vs.80).aspx

Did You Know? The first programming languages predate the modern computer. The 19th century saw the invention of "programmable" looms and player piano scrolls, both of which implemented examples ofdomain-specific languages. 

Page 23: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Did You Know ? All programming languages have some primitive building blocks for the description of data and the processes or transformations applied to them(like the addition of two numbers or the selection of an item from a collection). These primitives are defined by syntactic and semantic rules which describe their structure and meaning respectively.

Page 24: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://www.cfanatic.com/topic4267/Link:

Page 25: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Page 26: Fundamentalsofprogrammingfinal 121011003536-phpapp02

LOOPING STATEMENTS

http://eglobiotraining.com/

Page 27: Fundamentalsofprogrammingfinal 121011003536-phpapp02

Looping Statements

- Loops execute a block of code a specified number of times, or while a specified condition is true.

- in PHP, the following looping statements are used:

*The while Loop * The Do… While Loop * The For Loop *The Foreach Loop *Break and continue statement

http://eglobiotraining.com/

http://www.slideshare.net/ilakkiya/looping-statement

Page 28: Fundamentalsofprogrammingfinal 121011003536-phpapp02

THE WHILE LOOP

http://eglobiotraining.com/

While structure is another type of loop statements, where the condition is checked at first, the iteration will not stop even if the value changes while executing statements.

Form: While(condition){ code to be executed;}

http://www.slideshare.net/ilakkiya/looping-statement

Page 29: Fundamentalsofprogrammingfinal 121011003536-phpapp02

THE DO WHILE LOOP

Do while statement is same as the while statement , the only difference is that it evaluates the expression at the end.

http://eglobiotraining.com/

Form: do { code to be executed; } while (condition):

http://www.slideshare.net/ilakkiya/looping-statement

Page 30: Fundamentalsofprogrammingfinal 121011003536-phpapp02

THE FOR LOOP The for loop is used when you know in advance how

many times the script should run. Be for statement takes three expressions inside its

parentheses seperated by semi-colons. When the for loop executes, the following occurs:

The initializing expression is executed. This expression usually initializes oneor more loop counter, but the syntax allow expression any degree of complexity.

The condition expression is evaluated. Of the value of condition is true, the loop statements execute. If the value of condition is false, the for loop terminates.

http://www.slideshare.net/ilakkiya/looping-statement

http://eglobiotraining.com/

Page 31: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Form:

for {initialization; condition: increment ) { code to be executed }

http://www.slideshare.net/ilakkiya/looping-statement

Page 32: Fundamentalsofprogrammingfinal 121011003536-phpapp02

THE FOREACH LOOP For Each structure is a loop structure used for arrays

Form:foreach(array as value){ code to be executed}

Foreach (array as key => value){ code to be executed}

http://eglobiotraining.com/

http://www.slideshare.net/ilakkiya/looping-statement

Page 33: Fundamentalsofprogrammingfinal 121011003536-phpapp02

THE BREAK STATEMENT Break ends the execution of the for, for each,

while, do-while or switch statement.

http://eglobiotraining.com/

Form:* Break ( optional numeric argument)

http://www.slideshare.net/ilakkiya/looping-statement

Page 34: Fundamentalsofprogrammingfinal 121011003536-phpapp02

THE CONTINUE STATEMENT “Continue” is used to skip the current loop

iteration and continue with the next iteration of the loop. But “Break” is to exit from the whole loop.

http://eglobiotraining.com/

Form:* Break ( optional numeric argument)

http://www.slideshare.net/ilakkiya/looping-statement

Page 35: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://www.morrowland.com/apron/tutorials/cpp/cpp_for_loop/index.php

The for loop

Page 37: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://www.morrowland.com/apron/tutorials/cpp/cpp_do_while_loop/index.php

Do while loop

http://eglobiotraining.com/

Page 38: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Page 39: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://www.exforsys.com/tutorials/c-plus-plus/looping-in-c.html

While loop

Page 40: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Page 41: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://cprogramminglanguage.net/c-break-continue-statements.aspx

Break and continue

Page 42: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Page 43: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

http://www.w3schools.com/php/php_looping_for.asp

Foreach loop

Page 44: Fundamentalsofprogrammingfinal 121011003536-phpapp02

http://eglobiotraining.com/

Page 45: Fundamentalsofprogrammingfinal 121011003536-phpapp02

Slideshare account: sonsing11374541 http://www.slideshare.net/thinesonsing/newsf

eed

http://eglobiotraining.com/

Page 46: Fundamentalsofprogrammingfinal 121011003536-phpapp02

Submitted to : Prof. Erwin Globio

http://eglobiotraining.com/

Submitted by:

http://eglobiotraining.com/

In Partial fulfillment of requirements in Fundamental of Programming