Two-way selection. Branching and Looping

Size: px
Start display at page:

Download "Two-way selection. Branching and Looping"

Transcription

1 Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1. Conditional statements: Specifies a condition to execute a group of statements in a program. The control structures, if, if-else, nested if, if else ladder and switch, belongs to this category. 2. Iterative statements: Executes one or more statements repeatedly until a condition is met. The control structures: while, do while, and for loops, belong to this category. 3. Jump statements: Transfer of control from one part to another within the program. Ex. goto, break, continue and return. Two-way selection The basic decision statement in the computer is the two-way selection. The decision is described to the computer as a conditional statement that can be answered either true or false. If the answer is true, one or more action statements are executed. If the answer is false, then a different action or set of actions is executed. Regardless of which set of action is executed, the program continues with the next statement after the selection. The flow chart for the two-way decision logic is shown in Fig.A false Decision statement true false action true action Fig.A. Two-way decision logic Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 1

2 if statements The if statements executes a simple or compound statements, depending on whether or not an expression is true of false. The syntax to use if statements is: if(conditional expression) statements; //simple statement if(conditional expression) //compound statements statement 1; statement 1; statement 1; In the preceding syntaxes, a simple or compound statement (block of statements) is executed when the condition expression given in the if statement it turn out to be true. Otherwise, the program control passes to next statement. If the condition expression is false then the C compiler does not do anything. Note that the condition expression given in parenthesis, must be evaluated as true(non-zero value) or false(zero values). In addition, a compound statement must be provided by opening and closing braces. Examples: if(7) // a non zero value returns true if(0) //zero value returns false if(i==0) //True if i=0 other wise False if(i=0) //false because value of the expression is zero. *Note:- For programming examples, please refer text books. if-else statement The if-else statement executes a simple or compound statement when the conditional expression provided in the if statement is true. It executes another simple or compound statement, followed by the else statement, when the conditional expression is false. Syntax: if(conditional expression) simple or compound statement 1 else simple or compound statement 2 *Note:- For programming examples, please refer text books. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 2

3 Nested if statements (Multi-way selection) For the if-else, the statements may be any statement, including, another if-else. When an ifelse is included within an if-else, it is known as a nested if statement. The control of a program moves into the inner if statements when the outer if statement is evaluated to be true. Syntax: if(expression 1) if(expression 2) Statement 1 else Statement2 else Statement 3 Statement3 Expr1 Statement2 Expr2 Statement1 (a) code (b)logic Flow Syntax: if(conditional expression1) //Statement 1 to be executed in case the conditional expression1 is true if(conditional expression2) // Statement 2 to be executed in case the conditional expression2 is true if-else ladder(multi-way selection) When more than one if-else statements are used in a sequence, it is called as if-else ladder. The syntax is: if(conditional expression1) simple or compound statement else if(conditional expression2) simple or compound statement else if(conditional expression3) Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 3

4 simple or compound statement. else if(conditional expression n) simple or compound statement *Note:- For programming examples, please refer text books. Switch statements (Multi-way selection) A switch statement is a conditional statement that tests a value against different values. If the value is matched, the corresponding group of statements is executed. A switch statement begins with the switch keyword that followed by a value expression in the parenthesis( ). It is a combination of multiple case labels that must be separated by the break statement. Every case label contains a constant value that is matched against the value, which is specified in the switch expression. If the value is matched, the statements of that case label are executed. In addition, we can specify the default label, which is executed when the value specified in the switch expression, does not match with the given case labels. The syntax is: switch(expression) case value 1: statements break; case value 2: statements break; sase value 3: statements break; default: default statements break; *Note:- For programming examples, refer text books and class notes. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 4

5 Conditional operator (?:) or Ternary operator: is used to check a condition and select a value depending on the value of the condition. The selected value will be assigned to a variable which has the following form:- variable = (condition)? value1 : value2; Ex:- big = (a > b)? a : b; Repetition Concept of a loop The concept of a loop is shown in the flow chart in Fig.1. In this flow chart, the action is repeated over and over again. It never stops. Since the loop in fig. never stops, the actions will be repeated forever. We want the loop to end when the work is done. To make sure it ends, we must have a condition that controls the loop. In other words, we must desing the loop so that before or after each iteration, it checks to see if it is done. If it is not done, it repeats one more time; if it is done, it exits the loop. This test is known as a loop control expression. An action or a series of actions Fig.1. The concept of loop. Pretest and Post-Test loops Programming languages allow us to check the loop control expressions either before or after each iteration of the loop. In other words, we can have either a pre- or a posttest terminating condition. In a pretest loop, the condition is checked before we start and at the beginning of each iteration after the first. If the test condition is true, we execute the code; if the test condition is false, we terminate the loop. Examples: for loop, while loop. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 5

6 In a post-test loop, we always execute the code at least once. At the completion of the loop code, the loop control expression is tested. If the expression is true, the loop repeats; if the expressions is false, the loop terminates. The flowcharts in Fig.2. shows these two loop types. Example: do while Condition False An action or series of actions True An action or series of actions True Condition False a. Pretest Loop b. Post-test loop Fig.2. Pretest and post-test loops Pretest Loop Executions Initialization: 1 Number of tests: n+1 Minimum iterations: 0 n is the number of iterations. Post-test Loop Executions Initialization: 1 Number of tests: n Minimum iterations: 1 Table 1. Loop comparision Loops in C C has three loop statements: the while, the for, and the do while. The first two are pretest loops, and the do while is a post-test loop. We can use all of them for eventcontrolled and counter-controlled loops. Fig.6. shows these loop constructs. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 6

7 Loop statements while for do while Pretest loop Pretest loop post-test loop Fig.6. C loop constructs 1.The while loop The while statement is the pretest loop. It uses an expression to control the loop. Since it is a pretest loop, it tests the expressions before every iterations of the loop. The basic syntax of the while statement is shown in the fig.7. expression s While (expression) statement statement (a)flowchart (b)sample Code Fig.7. The while statement Note that the sample code in Fig.7 shows that the loop body is a single statement; that is, the body of the loop must be one, and only one, statement. If we want to include multiple statements in the body, we must put them in a compound statement(block). This concept is shown in the Fig.8. below. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 7

8 expression False While(expression). /*end while*/ Exit (a)flowchart (b) C language Fig.8. Compound while statement *Note:- For programming examples, please refer text books. 2.The for loop The for statement is a pretest loop that uses three expressions. The first expression contains any initialization statements, the second contains the limit-test expression, and the third contains the updating expression. Fig.9 shows the flow chart and an expanded interpretation, for a sample for statement. 1. Expression 1 is executed when the for starts. 2. Expression 2 is the limit test expression. As shown in the expanded flowchart, it is executed before every iteration. Since the for is a pretest loop, the body is not executed if the limit condition is false at the start of the loop. 3. Expression 3 is the update expressions. This means that you cannot use statements, such as return, in the for statement itself. 4. Like the while statements, the for statements does not need a semicolon. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 8

9 expr3 expr1 Effd f df expr2 f False expr1 expr2 False True True statement statement expr3 (a)flowchart (b) Expanded Flowchart Fig.9. for statement for(expr1;expr2;expr3) for(expr1;expr2;expr3) (a)simple for statement (b)compound for statement *Note:- For programming examples, please refer text books. Nested for loops Any statement, even another for loop, can be included in the body of a for statement. In other words, a for loop inside for loop is called nested for. For(expr1;expr2;expr3) //Outer for loop for(expr1;expr2;expr3) //Inner for loop statements; //end of inner for //end of outer for *Note:- For programming examples, please refer text books. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 9

10 2.1 Variations in for loop 1.In for loop, the expression i<=n can be replaced by the expression i<n+1. For example, consider for(i=1; i<=5 ; i++) Printf( %d, i); //Output: //can also be written as for(i=0 ; i<6 ; i++) Printf( %,i); //Output: The initialization expression can be moved just before the loop and updation expression can be shifted to end of body loop. For ex. for(i=1; i<=5 ; i++) i=1 Printf( %d, i); is same as for( ; i<=5 ; ) Printf( %d, i); i++; 3. For loop should not end with semicolon. For(i=1; i<=5 ; i++) Printf( %d, i) ; Observe that semicolon in the body of the loop is treated as NULL statement. So, for all the values of i=1,2,3,4,5 the NULL statement is executed which does nothing. Finally, i will be 6 and control comes out of for loop. 4. The initialization expression expr1, limit test expression expr2 and update expression expr3 are optional in the for loop. For ex. for( ; ;) printf( \n ); Whenever limit test expression is not there in the for loop, it is treated as infinite loop. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 10

11 3. The do while statement The do while statement is a post-test loop. Like the while and for loops, it also uses an expression to control the loop, but it tests this expression after the execution of the body. The format of the do.while statement is shown in Fig.10. statement do statement expression while ( expression ); true false do expression true false (a)flowchart while (expression ); (b)sample Code Comparison of Loop Control Structures for loop while loop do while loop 1.A for loop is used to execute and repeat a statement block depending on a condition at the beginning of the loop. Example for(i=1; i<=10; i++) A while loop is used to execute and repeat a statement block depending on a condition which is evaluated at the beginning of the loop. Example i=1; A do while loop is used to execute and repeat a statement block depending on a condition which is evaluated at the end of the loop. Example i=1; Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 11

12 s=s+i; p=p*i; 2. A variable value is initialized at the beginning of the loop and is used in the condition. 3. A statement to change the value of the condition or to increment the value of the variable is given at the beginning of the loop. 4.The statement block will not be executed when the value of the condition is false. 5.A for loop is commonly used by many programmers. while(i<=10) s=s+i; p=p*i; i++; A variable value is initialized at the beginning or before the loop and is used in the condition. A statement to change the value of the condition or to increment the value of the variable is given at the inside of the loop. The statement block will not be executed when the value of the condition is false. A while loop is also widely used by many programmers. do s=s+i; p=p*i; i++; while(i<=10); A variable value is initialized before the loop or assigned inside the loop and is used in the condition. A statement to change the value of the condition or to increment the value of the variable is given at the inside of the loop. The statement block will not be executed when the value of the condition is false, but the block is executed at least once irrespective of the value of the condition. A do while loop is used in some cases where the condition need to be checked at the end of the loop. Jump statements Jump statements are the statements that transfer control from one part of the program to another. The jump statements supported by C are follows: break statements continue statements goto statements return statements break statement/ Jump statements related to looping The break statement is used to break any type of loop as well as switch statement. Breaking a loop means terminating the loop. It has the following form: Example: break; Printf( Press B to break, any other key to continue ); for(i=1 ; i<=80 ; i++) Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 12

13 ch = getche(); if (ch == B ) break; control is transferred to the end of block continue statement/ Jump statements related to looping The continue statement is used to transfer the control to the beginning of a statement block in a loop. In other words, a break statement breaks the entire loop, but a continue statement breaks the current iteration. That is, the continue statement breaks the current execution of a loop condition and then continue the loop with next condition. If has the following form: Example: continue; for(i=1 ; i<=80 ; i++) ch = getche(); if (ch == C ch == c ) control is transferred to the beginning of the block. printf( C for continue is pressed ); continue; goto statement The goto statement is an unconditional transfer of control statement. It is used to transfer the control from one part of the program to another. The place to which the control is transferred is identified by a statement label. It has the following form: goto label; where label is the statement label which is available anywhere in the program. Example: ; goto display; ; ; display; ; Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 13

14 exit( ) Function The exit( ) function is used to transfer the control to the end of a program (i.e to terminate the program execution). It uses one argument in ( ) and the value is zero for normal termination or non-zero for abnormal termination. For example. if (n<0) printf( Factorial in not available for negative numbers ); exit(0); Note that the program execution is terminated when the value of the variable n is negative. The compiler directive #include<stdlib> is used when this function is used in a program. return: It is used to return the control to the calling function with/without a value. For example, if a function is not returning any value, use the return keyword If a function is returning a value, then return; return value; Question Bank 1. What is a two way selection statement? Explain with an example. 2. With a suitable example program, demonstrate the working of if-else statement 3. What are multi-way selection/decision making statements? Explain them 4. What is nested if? Explain with a suitable program. 5. What is if-else ladder? Explain with a suitable program. 6. What is a switch? With syntax explain with an example program. 7. What is a loop? How loops are classified in C? 8. Explain the working of for, while and do_while loops with syntax and suitable example programs. 9. What is the difference between while and do_while? 10. Differentiate between for, while and do_while? 11. What are pre-test loops and post-test loops? Explain with examples. 12. What are jump statements? Explain the different types of jump statements available in C. 13. Explain the following jump statements. i.goto ii.break iii.continue. 14. Where and why break and continue statements are used in C? 15. What are Ternary operators? Explain them. Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 14

15 Sunil Kumar B, Dept of CSE, NCET, Bengaluru. 15

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Senem Kumova Metin & Ilker Korkmaz 1

Senem Kumova Metin & Ilker Korkmaz 1 Senem Kumova Metin & Ilker Korkmaz 1 A loop is a block of code that can be performed repeatedly. A loop is controlled by a condition that is checked each time through the loop. C supports two categories

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Selection Statements

Selection Statements Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

UEE1302 (1102) F10 Introduction to Computers and Programming

UEE1302 (1102) F10 Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU UEE1302 (1102) F10 Introduction to Computers and Programming Programming Lecture 03 Flow of Control (Part II): Repetition while,for & do..while Learning

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition Objectives In this chapter, you will learn about: Representing algorithms Examples of algorithmic problem

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Chapter 5 Programming Statements. Chapter Table of Contents

Chapter 5 Programming Statements. Chapter Table of Contents Chapter 5 Programming Statements Chapter Table of Contents OVERVIEW... 57 IF-THEN/ELSE STATEMENTS... 57 DO GROUPS... 58 IterativeExecution... 59 JUMPING... 61 MODULES... 62 Defining and Executing a Module....

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Fundamentals of Programming and Software Development Lesson Objectives

Fundamentals of Programming and Software Development Lesson Objectives Lesson Unit 1: INTRODUCTION TO COMPUTERS Computer History Create a timeline illustrating the most significant contributions to computing technology Describe the history and evolution of the computer Identify

More information

MATLAB Programming. Problem 1: Sequential

MATLAB Programming. Problem 1: Sequential Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus [email protected] The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

1 Introduction. 2 Overview of the Tool. Program Visualization Tool for Educational Code Analysis

1 Introduction. 2 Overview of the Tool. Program Visualization Tool for Educational Code Analysis Program Visualization Tool for Educational Code Analysis Natalie Beams University of Oklahoma, Norman, OK [email protected] Program Visualization Tool for Educational Code Analysis 1 Introduction

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10 Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control Reading: Bowman, Chapters 16 CODE BLOCKS A code block consists of several lines of code contained between a BEGIN

More information

PHP Tutorial From beginner to master

PHP Tutorial From beginner to master PHP Tutorial From beginner to master PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

More information

Writing Control Structures

Writing Control Structures Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

More information

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Overview. Basic Structure and Syntax of PL/SQL PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension

More information

Statements and Control Flow

Statements and Control Flow Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

2 SYSTEM DESCRIPTION TECHNIQUES

2 SYSTEM DESCRIPTION TECHNIQUES 2 SYSTEM DESCRIPTION TECHNIQUES 2.1 INTRODUCTION Graphical representation of any process is always better and more meaningful than its representation in words. Moreover, it is very difficult to arrange

More information

Chapter 5. Selection 5-1

Chapter 5. Selection 5-1 Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End

More information

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script Shell Programming Shell Scripts (1) Basically, a shell script is a text file with Unix commands in it. Shell scripts usually begin with a #! and a shell name For example: #!/bin/sh If they do not, the

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int. Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Module 2 Stacks and Queues: Abstract Data Types

Module 2 Stacks and Queues: Abstract Data Types Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

More information

Computer Programming I

Computer Programming I Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement (e.g. Exploring

More information

LOOPS CHAPTER CHAPTER GOALS

LOOPS CHAPTER CHAPTER GOALS jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement

More information

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha Algorithm & Flowchart & Pseudo code Staff Incharge: S.Sasirekha Computer Programming and Languages Computers work on a set of instructions called computer program, which clearly specify the ways to carry

More information

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

More information

Flowchart Techniques

Flowchart Techniques C H A P T E R 1 Flowchart Techniques 1.1 Programming Aids Programmers use different kinds of tools or aids which help them in developing programs faster and better. Such aids are studied in the following

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

C PROGRAMMING FOR MATHEMATICAL COMPUTING

C PROGRAMMING FOR MATHEMATICAL COMPUTING UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions

More information

1.3 Conditionals and Loops

1.3 Conditionals and Loops A Foundation for Programming 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops Math primitive data

More information

TIP: To access the WinRunner help system at any time, press the F1 key.

TIP: To access the WinRunner help system at any time, press the F1 key. CHAPTER 11 TEST SCRIPT LANGUAGE We will now look at the TSL language. You have already been exposed to this language at various points of this book. All the recorded scripts that WinRunner creates when

More information

Bash shell programming Part II Control statements

Bash shell programming Part II Control statements Bash shell programming Part II Control statements Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email [email protected]

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

More information

C LANGUAGE TUTORIAL. Version 2.8 - Sept 8, 1996

C LANGUAGE TUTORIAL. Version 2.8 - Sept 8, 1996 C LANGUAGE TUTORIAL This tutorial teaches the entire C programming language. It is composed of 13 chapters which should be studied in order since topics are introduced in a logical order and build upon

More information

4.8 Thedo while Repetition Statement Thedo while repetition statement

4.8 Thedo while Repetition Statement Thedo while repetition statement 1 4.8 hedo while Repetition Statement hedo while repetition statement Similar to thewhile structure Condition for repetition tested after the body of the loop is performed All actions are performed at

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

Notes on Algorithms, Pseudocode, and Flowcharts

Notes on Algorithms, Pseudocode, and Flowcharts Notes on Algorithms, Pseudocode, and Flowcharts Introduction Do you like hot sauce? Here is an algorithm for how to make a good one: Volcanic Hot Sauce (from: http://recipeland.com/recipe/v/volcanic-hot-sauce-1125)

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

Programming and Software Development (PSD)

Programming and Software Development (PSD) Programming and Software Development (PSD) Course Descriptions Fundamentals of Information Systems Technology This course is a survey of computer technologies. This course may include computer history,

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

[Refer Slide Time: 05:10]

[Refer Slide Time: 05:10] Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture

More information

KS3 Computing Group 1 Programme of Study 2015 2016 2 hours per week

KS3 Computing Group 1 Programme of Study 2015 2016 2 hours per week 1 07/09/15 2 14/09/15 3 21/09/15 4 28/09/15 Communication and Networks esafety Obtains content from the World Wide Web using a web browser. Understands the importance of communicating safely and respectfully

More information

Lecture 1 Introduction to Java

Lecture 1 Introduction to Java Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First

More information

Cobol. By: Steven Conner. COBOL, COmmon Business Oriented Language, one of the. oldest programming languages, was designed in the last six

Cobol. By: Steven Conner. COBOL, COmmon Business Oriented Language, one of the. oldest programming languages, was designed in the last six Cobol By: Steven Conner History: COBOL, COmmon Business Oriented Language, one of the oldest programming languages, was designed in the last six months of 1959 by the CODASYL Committee, COnference on DAta

More information

Fundamentals of Java Programming

Fundamentals of Java Programming Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors

More information

Course Title: Software Development

Course Title: Software Development Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

C Language Tutorial. Version 0.042 March, 1999

C Language Tutorial. Version 0.042 March, 1999 C Language Tutorial Version 0.042 March, 1999 Original MS-DOS tutorial by Gordon Dodrill, Coronado Enterprises. Moved to Applix by Tim Ward Typed by Karen Ward C programs converted by Tim Ward and Mark

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Translating C code to MIPS

Translating C code to MIPS Translating C code to MIPS why do it C is relatively simple, close to the machine C can act as pseudocode for assembler program gives some insight into what compiler needs to do what's under the hood do

More information

Python Loops and String Manipulation

Python Loops and String Manipulation WEEK TWO Python Loops and String Manipulation Last week, we showed you some basic Python programming and gave you some intriguing problems to solve. But it is hard to do anything really exciting until

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Unix Scripts and Job Scheduling

Unix Scripts and Job Scheduling Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh [email protected] http://www.sis.pitt.edu/~spring Overview Shell Scripts

More information

Performing Simple Calculations Using the Status Bar

Performing Simple Calculations Using the Status Bar Excel Formulas Performing Simple Calculations Using the Status Bar If you need to see a simple calculation, such as a total, but do not need it to be a part of your spreadsheet, all you need is your Status

More information

Command Scripts. 13.1 Running scripts: include and commands

Command Scripts. 13.1 Running scripts: include and commands 13 Command Scripts You will probably find that your most intensive use of AMPL s command environment occurs during the initial development of a model, when the results are unfamiliar and changes are frequent.

More information

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents

C Coding Style Guide. Technotes, HowTo Series. 1 About the C# Coding Style Guide. 2 File Organization. Version 0.3. Contents Technotes, HowTo Series C Coding Style Guide Version 0.3 by Mike Krüger, [email protected] Contents 1 About the C# Coding Style Guide. 1 2 File Organization 1 3 Indentation 2 4 Comments. 3 5 Declarations.

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Unit 6. Loop statements

Unit 6. Loop statements Unit 6 Loop statements Summary Repetition of statements The while statement Input loop Loop schemes The for statement The do statement Nested loops Flow control statements 6.1 Statements in Java Till now

More information

GRID SEARCHING Novel way of Searching 2D Array

GRID SEARCHING Novel way of Searching 2D Array GRID SEARCHING Novel way of Searching 2D Array Rehan Guha Institute of Engineering & Management Kolkata, India Abstract: Linear/Sequential searching is the basic search algorithm used in data structures.

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

Statements and Control Flow

Statements and Control Flow 3 Statements and Control Flow The program examples presented until now have executed from top to bottom without making any decisions. In this chapter, we have programs select among two or more alternatives.

More information

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16 s schedule Lecture 7 - C Programming for the Atmel AVR School of Electrical, l Computer and Telecommunications i Engineering i University of Wollongong Australia Week Lecture (2h) Tutorial (1h) Lab (2h)

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More information

Programming Database lectures for mathema

Programming Database lectures for mathema Programming Database lectures for mathematics students April 25, 2015 Functions Functions are defined in Postgres with CREATE FUNCTION name(parameter type,...) RETURNS result-type AS $$ function-body $$

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Chapter 13: Program Development and Programming Languages

Chapter 13: Program Development and Programming Languages 15 th Edition Understanding Computers Today and Tomorrow Comprehensive Chapter 13: Program Development and Programming Languages Deborah Morley Charles S. Parker Copyright 2015 Cengage Learning Learning

More information

The While Loop. Objectives. Textbook. WHILE Loops

The While Loop. Objectives. Textbook. WHILE Loops Objectives The While Loop 1E3 Topic 6 To recognise when a WHILE loop is needed. To be able to predict what a given WHILE loop will do. To be able to write a correct WHILE loop. To be able to use a WHILE

More information

Problem Solving Basics and Computer Programming

Problem Solving Basics and Computer Programming Problem Solving Basics and Computer Programming A programming language independent companion to Roberge/Bauer/Smith, "Engaged Learning for Programming in C++: A Laboratory Course", Jones and Bartlett Publishers,

More information