Announcements Exam 1 Thursday Everything through Lab 5 50 minutes

Slides:



Advertisements
Similar presentations
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Advertisements

Control Structures. Decision Making Structures The if and if…else are all selection control structures that introduce decision-making ability into a program.
Topic 03 Control Statements Programming II/A CMC2522 / CIM2561 Bavy Li.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
Loops – While, Do, For Repetition Statements Introduction to Arrays
Switch Statement switch (month) { case 9: case 4: case 6: case 11: days = 30; break; case 2: days = 28; if (year % 4 == 0) days = 29; break; default: days.
1 CS 105 Lecture 6 While Loops Wed, Feb 16, 2011, 5:13 pm.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
1 CS 105 Lecture 5 Logical Operators; Switch Statement Wed, Feb 16, 2011, 5:11 pm.
1 CS 105 Lecture 7 For & Do-While Loops Sun, Feb 27, 2011, 2:16 pm.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Chapter 5 Loops.
The for Loop Syntax: for ( expression1 ; condition ; expression2 ) statement ; for ( expression1 ; condition ; expression2 ) { statement ; } Same as: expression1.
Announcements Exam 1 Tuesday July minutes 10 % of Total Grade Covers Everything through Lecture 05. –Includes Quiz 1 Topics (terminology, variables,
Chapter 4: Control Structures II
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Java Prepared by Gary Langner Types of Loops u for loop (entrance controlled) –do an action for a definite number of times u while loop (entrance controlled.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
CONTROL STRUCTURE Chapter 3. CONTROL STRUCTURES ONE-WAY SELECTION Syntax: if (expression) statement Expression referred to as decision maker. Statement.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Quiz 1 Exam 1 Next Monday. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) System.out.println(“You have an A!” ); else System.out.println(“You.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
Java Fundamentals 4.
CSC111 Quick Revision.
The switch Statement, and Introduction to Looping
Announcements Quiz 1 Posted on blackboard
Introduction to programming in java
Chapter 6 More Conditionals and Loops
Chapter 5: Control Structures II
Repetition-Counter control Loop
CiS 260: App Dev I Chapter 4: Control Structures II.
Repetition-Sentinel,Flag Loop/Do_While
Chapter 5: Control Structures II
SELECTION STATEMENTS (1)
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
Announcements Exam 1 Grades Posted on Blackboard.
Chapter 6 More Conditionals and Loops
Selection (if-then-else)
Outline Boolean Expressions The if Statement Comparing Data
Announcements Exam 1 Thursday 50 minutes 10 % of Total Grade
Control Statements Loops.
CS 200 Loops Jim Williams, PhD.
Announcements Exam 1 Grades Posted on Blackboard.
The for Loop Syntax: Same as: for (expression1;condition; expression2)
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
CS2011 Introduction to Programming I Selections (I)
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 14, 2011
Control Statements Loops.
Repetition Statements
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Welcome back! October 11, 2018.
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.
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Announcements Exam 1 Grades Posted on blackboard Average: 83.26
Presentation transcript:

Announcements Exam 1 Thursday Everything through Lab 5 50 minutes 15 % of Total Grade Covers Everything through Lecture last Week General Topics (terminology, variables, constants, basics) if-then-else Compound statements Relational operators Equality operators and .equals() Logical operators Switch/Case Statements

Iteration Iteration (Looping): Performing a Series of Statements Multiple Times until Some Condition Is Met. Eliminates the Need for Redundant Coding or Function Calls Many Ways to Loop in JAVA

The while Loop Syntax: while (condition) statement; while (condition) { statement; }

while Example final int MAX = 100; int counter = 0; while (counter < MAX) { System.out.println( counter + “ “ ); counter++; }

Example while Loop int numEmployees,curNum = 0; System.out.print(“Enter Number of Employees: “); numEmployees = scan.nextInt(); if (numEmployees > 0) { while (curNum < numEmployees) System.out.println( “Welcome to CorpLand!” ); curNum++; }

The for Loop Syntax: Same as: for (expression1;condition; expression2) statement; { } Same as: expression1; while (condition) expression2;

Example for Loop System.out.println( “Welcome to CorpLand!” ); } int numEmployees,curNum; System.out.print(“Enter Number of Employees: “); numEmployees = scan.nextInt(); if (numEmployees > 0) { for (curNum = 0; curNum < numEmployees;curNum++) System.out.println( “Welcome to CorpLand!” ); }

Looping for Input char letterEntered = ‘A’; String stringE; while (letterEntered != ‘Z’) { System.out.print(“Enter a letter: “); stringE = scan.next(); letterEntered = stringE.charAt(0); }

Looping until Flag boolean noMoreData(); boolean done = false; … while (!done) { // do a bunch of stuff if (noMoreData() == true) done = true; } System.out.println(“ We’re all through – thank you!”);

Nested Loops int i , j ; for (i=0; i < 10; i++) { for (j=0; j < 10; j++) System.out.print(i); System.out.print(j); System.out.print(“ “ ); } System.out.println();

The do-while Loop Syntax do statement; while (condition); { }

do-while Example char letterEntered; String stringE; do { System.out.print(“Enter a letter: “); stringE = scan.next(); letterEntered = stringE.charAt(0); } while (letterEntered != ‘Z’);

What Is This? while (!stringEntered.equals(“apple”)) { System.out.println( “Enter a red fruit: “); stringEntered = scan.next(); } while (!stringEntered.equals(“banana”)) System.out.println(“Enter a yellow fruit: “); while (!stringEntered.equals(“pomegranate”)) System.out.println(“Enter a random fruit: “);

What Is This? for (i = 0; i < 10 ; i++) System.out.println( “Interesting, isn’t it?”); while (answer.charAt(0) != ‘D’) { System.out.print( “Enter an answer: “); answer = scan.next(); }

What Is This? void kingsChair(int loopCounter) { int num; for(num = 0; num < loopCounter; num++) System.out.println(“AAAAAAAAAAAAAAAAAAAAAAAAAA”); }

Announcements Exam 1 Thursday Everything through Lab 5 50 minutes 15 % of Total Grade Covers Everything through Lecture last Week General Topics (terminology, variables, constants, basics) if-then-else Compound statements Relational operators Equality operators and .equals() Logical operators Switch/Case Statements