Announcements Exam 1 Thursday 50 minutes 10 % of Total Grade

Slides:



Advertisements
Similar presentations
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
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.
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
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
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
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
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.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Java Fundamentals 4. Java Programming: From Problem Analysis to Program Design, Second Edition2 Parsing Numeric Strings  Integer, Float, and Double are.
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:
Java Fundamentals 4.
CSC111 Quick Revision.
Chapter 4 Repetition Statements (loops)
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
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 5 Repetition.
Selection (if-then-else)
Control Statements Loops.
Announcements Exam 1 Thursday Everything through Lab 5 50 minutes
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.
Lecture Notes – Week 2 Lecture-2
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
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.
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
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 50 minutes 10 % of Total Grade Covers Everything through Lecture Last Week Quiz 1 Topics (terminology, variables, constants, basics) if-then-else Compound statements Relational operators 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”); }