JAVA PROGRAMMING Control Flow. Jeroo: Finish Activities 1-7 Finish InputTest program w/changes.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Control Structures.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
PSEUDOCODE & FLOW CHART
Control Structures Corresponds with Chapters 3 and 4.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
ITEC113 Algorithms and Programming Techniques
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Introduction to Computer Programming Decisions If/Else Booleans.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
The switch Statement, DecimalFormat, and Introduction to Looping
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Jaeki Song ISQS6337 JAVA Lecture 04 Control Structure - Selection, and Repetition -
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
Previously Repetition Structures While, Do-While, For.
ITEC113 Algorithms and Programming Techniques
Branches and Program Design
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
CSE 1341 Honors Note Set 05 Professor Mark Fontenot Southern Methodist University.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Control Structures RepetitionorIterationorLooping Part I.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Decision Making and Branching (cont.)
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Control Statements: Part1  if, if…else, switch 1.
FOR LOOPS "LOOP FOR A SET NUMBER OF TIMES.". FOR ( START_VALUE; END_VALUE; INCREMENT_NUMBER ) { //YOUR_CODE_HERE } So after the word "for" (in lowercase)
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
CSE 110 Midterm Review Hans and Carmine. If Statements If statements use decision logic In order to properly use if statements relational operators must.
Chapter 4: Control Structures I
CSC111 Quick Revision.
while Repetition Structure
Chapter 4: Control Structures I
PROGRAM CONTROL STRUCTURE
Ch 7: JavaScript Control Statements I.
Chapter 4: Making Decisions.
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Chapter 4: Control Structures I
IF if (condition) { Process… }
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Program Flow.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

JAVA PROGRAMMING Control Flow

Jeroo: Finish Activities 1-7 Finish InputTest program w/changes

Review test results

Conditional Statements: Statements are executed based on a condition that is evaluated.

Conditional Statements: if if else if else if while do for switch break continue

Conditional Statements “if”: if (condition) statement or If (condition) { statements }

Conditional Statements “if”: if (yourGrade >= 90) System.out.println(“Your grade is an ‘A’”); if (yourGrade < 60) System.out.println(“Your grade is an ‘F’”);

Conditional Statements “if”: yourGrade >= 90 Print “Your grade is an A” termGrade += yourGrade NO YES

Conditional Statements “if”: if (yourGrade >= 90) { termGrade += yourGrade; System.out.println(“You’re grade is an ‘A’”); }

Conditional Statements “if-else”: yourGrade >= 90 Print “Your grade is an A” termGrade += yourGrade NO YES Print “Try harder next time”

Conditional Statements “if-else”: if (yourGrade >= 90) { termGrade += yourGrade; System.out.println(“Your grade is an ‘A’”); } else { System.out.println(“Try harder next time”); }

Conditional Statements “if-else-if”: termGrade += yourGrade if (termGrade >= 90) { System.out.println(“You’re grade is an ‘A’”); } else if (termGrade >= 80) { System.out.println(“You’re grade is an ‘B’”); } else if (termGrade >= 70) { System.out.println(“You’re grade is an ‘C’”); } else if (termGrade >= 60) { System.out.println(“You’re grade is an ‘D’”); } else { System.out.println(“You’re grade is an ‘F’”); }

Conditional Statements “if-else-if”: yourGrade >= 90 NO YES Print “Your grade is an A” yourGrade >= 80 yourGrade >= 70 Print “Your grade is an B” Print “Your grade is an C” NO YES

While Loop customerCount < 20 customerCount ++ “Ride Full” doorSensor True NO YES NO YES

While Loop: While (customerCount < 20) { If (doorSensor) customerCount ++; } System.out.println(“Ride is Full”);

Do While Loop: customerCount < 20 customerCount ++ “Ride Full” doorSensor True NO YES NO YES

Do While Loop: do { If (doorSensor) customerCount ++; } While (customerCount < 20) System.out.println(“Ride is Full”);

For Loop: for (int i = 1; i <= 10; i++) System.out.println(i);

switch: Scanner in = new Scanner(System.in); System.out.print(“Select an option (1, 2, 3, 4) “); int choice = in.nextInt(); switch (choice) { case 1: … break; case 2: … break; case 3: … break; case 4: … break; Default: … Break; }

Flowcharting:

Begin Just a Marker to show where the program begins. A A A connector to another area on the same page of a flowchart. 1 1 A connector to another page of the flowchart. END Just a Marker to show where the program ends.

Flowcharting : ? Yes or True No or False ? Yes or True No or False Decision based on a comparison to cause a branch in the logic.

Flowcharting : Do this! Equations, Declarations, Initializations, etc

Flowcharting : I/O to the program INPUT OUTPUT

Flowcharting : Flowchart the following scenario to be written in Java code: Grade Averaging Program: Prompt user to Input a grade Input the grade Sum the grade into a grade total Count the number of grades entered Repeat (loop!) until user enters a set value to terminate input process Divide the grade total by the count Display the average with text to explain the result