Instructor: SIR MUHAMMAD NAVEED Created by: ARSLAN AHMED SHAAD ( ) MUHAMMAD BILAL ( ) ISIT:

Similar documents
Le L c e t c ur u e e 3 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Control Statements

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

CS313D: ADVANCED PROGRAMMING LANGUAGE

Accelerating Information Technology Innovation

PROGRAMMING FUNDAMENTALS

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

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

CSC Java Programming, Fall Java Data Types and Control Constructs

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

OER on Loops in C Programming

ECE 122. Engineering Problem Solving with Java

CompSci 125 Lecture 11

Java Control Statements

SCoLang - Language Reference Manual

Loops. In Example 1, we have a Person class, that counts the number of Person objects constructed.

DELHI PUBLIC SCHOOL TAPI

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

Introduction to Programming Using Java (98-388)

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

CS1004: Intro to CS in Java, Spring 2005

Flow Control. CSC215 Lecture

Control Structures in Java if-else and switch

Advanced Computer Programming

Information Science 1

Review for Test 1 (Chapter 1-5)

Introduction. C provides two styles of flow control:

Java Programming. Atul Prakash

SELECTION. (Chapter 2)

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Object-Oriented Programming in Java

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

8. Decision-Making Statements. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

UNIT 3

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

204111: Computer and Programming

egrapher Language Reference Manual

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

THE CONCEPT OF OBJECT

Control Structures in Java if-else and switch

DECISION CONTROL AND LOOPING STATEMENTS

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Control Flow Statements

5 The Control Structure Diagram (CSD)

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

Computer Programming I - Unit 5 Lecture page 1 of 14

Prepared by: Shraddha Modi

Information Science 1

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Language Proposal: tail

More Programming Constructs -- Introduction

Introduction to Java & Fundamental Data Types

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Scope of this lecture. Repetition For loops While loops

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

Programming with Java

CS313D: ADVANCED PROGRAMMING LANGUAGE

COMP 202 Java in one week

Computer Components. Software{ User Programs. Operating System. Hardware

Introduction to C/C++ Lecture 3 - Program Flow Control

Grouping objects. Main concepts to be covered

CS111: PROGRAMMING LANGUAGE II

Connecting with Computer Science, 2e. Chapter 15 Programming II

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Following is the general form of a typical decision making structure found in most of the programming languages:

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 8. Conditional Processing

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CS110D: PROGRAMMING LANGUAGE I

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Chapter 7 Control I Expressions and Statements

YOLOP Language Reference Manual

Loops. CSE 114, Computer Science 1 Stony Brook University

5. Selection: If and Switch Controls

SNS COLLEGE OF ENGINEERING,

While Loops CHAPTER 5: LOOP STRUCTURES. While Loops. While Loops 2/7/2013

REPETITION CONTROL STRUCTURE LOGO

3. Java - Language Constructs I

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Software Programming Objectives

Chapter 3. Flow of Control. Branching Loops exit(n) method Boolean data type and expressions

Chapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );

Chapter 3. Iteration

The Design of C: A Rational Reconstruction (cont.)

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Decision Making and Loops

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

The Arithmetic Operators

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Java language has a wide variety of modifiers, including the following:

Programming Fundamentals

Transcription:

Instructor: SIR MUHAMMAD NAVEED Created by: ARSLAN AHMED SHAAD ( 1163135 ) MUHAMMAD BILAL (1163122 ) ISIT:www.techo786.wordpress.com

CHAPTER: 3 NOTE: CONTROL STATEMENTS Question s Given below are Long Question s and also contains Definitions. Java Control Flow Statements Java Control statements control the order of execution in a java program, based on data values and conditional logic. There are three main categories of control flow statements: : if, if-else and switch. : while, do-while and for. : break, continue, return, try-catch-finally and assert. We use control statements when we want to change the default sequential order of execution If Statement : The if statement executes a block of code only if the specified expression is true. If the value is false, then the if block is skipped and execution continues with the rest of the program. If statement has the following syntax: if (<conditional expression>) <statement action>

EXAMPLE If else Statement In if-else statements, if the specified condition in the if statement is false, then the statement after the else keyword (that can be a block) will execute. Note that the conditional expression must be a Boolean expression. If-else statement has the following syntax: if (<conditional expression>) <statement action> else <statement action> EXAMPLE Switch case Statement

The switch statement is control flow statement that start with an expression and transfer control to one of the case statements on the basis of the value of expression. The keyword "switch" is followed by an expression that should evaluates to byte, short, char or int primitive data types, only. Break statement is used at the end of every case. Default label is permitted at the end to improve readability. Switch statement has following syntax switch(control_expression){ case expression 1: <statement>; case expression 2: <statement>;...... case expression n: <statement>; default: <statement>; }//end switch EXAMPLE

Loop: : Loop allow us to repeat the statement or set of statement on the basis of some condition. Loop is used to repeatedly execute the line of code or block of code. It is also called repetition/ iteration Types of Loop For loop While loop Do while loop For each loop For loop For loop is used to repeatedly execute statement or block of statement for a specified number of times. For loop is suitable when number of iteration are predefined. For loop has following syntax for(initialization;condition;incr/decr){ //code to be executed }

EXAMPLE While loop While loop is a statement that repeat the execution of statements or set of statements after while until the condition remains true While loop has following syntax while(condition){ //code to be executed }

EXAMPLE Do while loop Working of do while loop is most likely as while loop except that condition is evaluated at the bottom of loop in do while Do while loop has following syntax do{ //code to be executed }while(condition);

EXAMPLE For each loop When we loop through collection and arrays we use for each loop. It is easier to use than simple for loop because we don't need to increment value and use subscript notation. For each loop has following syntax for(type var:array){ //code to be executed }

EXAMPLE Q: What for each loop cannot do? Answer: 1: for each loop cannot iterate background through the element of an array 2: cannot use the single loop counter for two different arrays. 3: we cannot iterate through array using get () method. :

Transfer statements are used to unconditionally transfer the program control to another part of the program. Java provides the following jump statements: break statement continue statement return statement Break Statement The Java break is used to break loop or switch statement. It breaks the current flow of the program at specified condition. Syntax Jump-statement; break; Continue Statement The continue statement is used when you want to continue running the loop with the next iteration and want to skip the rest of the statements of the body for the current iteration. Syntax jump-statement; continue; Return Statement The return statement is used to immediately quit the current method and return to the calling method. Thank You for visiting : www.vbforstudent.tk Go to this link for new updates on Technology and Education: www.techo786.wordpress.com