Agenda Remarks about last homework for loop Nested for loop Flowchart

Slides:



Advertisements
Similar presentations
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Advertisements

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,
Control Structures. Decision Making Structures The if and if…else are all selection control structures that introduce decision-making ability into a program.
08 Deterministic iteration1May Deterministic iteration CE : Fundamental Programming Techniques.
Chapter 2- Visual Basic Schneider
Computer Science 1620 Loops.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
© 2007 Lawrenceville Press Slide 1 Chapter 6 The while Statement  Loop structure that executes a set of statements as long as a condition is true  The.
CONTROL STATEMENTS IF-ELSE, SWITCH- CASE Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian
Chapter 2 - Algorithms and Design
Chapter 5 Loops.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Topics Logical Operators (Chapter 5) Comparing Data (Chapter 5) The conditional operator The switch Statement The for loop Nested Loops.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Debugging and Testing Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
UCT Department of Computer Science Computer Science 1015F Iteration
CompSci 230 S Programming Techniques
REPETITION CONTROL STRUCTURE
Chapter 2- Visual Basic Schneider
Chapter 2 Assignment and Interactive Input
Chapter 6 More Conditionals and Loops
Computer Programming I
Loop Structures.
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Chapter 5: Loops and Files.
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
SELECTION STATEMENTS (1)
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Chapter 6 The while Statement
Chapter 5 Repetition.
TOPIC 4: REPETITION CONTROL STRUCTURE
Outline Altering flow of control Boolean expressions
Chapter 9 Control Structures.
Pseudocode & Flowcharts
Chapter 4: Loops and Files
1) C program development 2) Selection structure
Chapter 2- Visual Basic Schneider
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Lec 4: while loop and do-while loop
Chapter 5: Control Structure
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
What output is produced by the following fragment?
No Yes START Do you live in Scotland? Take umbrella See last Flowchart
Developing a Program.
Programming Right from the Start with Visual Basic .NET 1/e
Chapter 2 - Algorithms and Design
Agenda Packages and classes Types and identifiers Operators
Conditionals and Loops
C++ for Engineers and Scientists Second Edition
ICS103: Programming in C 5: Repetition and Loop Statements
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Agenda Remarks about last homework for loop Nested for loop Flowchart Debugging techniques breakpoint; variable trace; println Homework

Remarks on the last homework Do NOT declare variable inside the loop Good design needs some thinking and trying - if you want the user to play until he/she gets it right?...what if it is hard to be right? - the program quits when user enters some number? Is it the way we play games?

for Loop for Loop executes a set of statements a fixed number of times. The for statement takes the form: for (<initialization>; <condition>; <increment>) { <statements> } example for (int i = 1; i <= 10; i++) { System.out.println(i); How can this example change to equivalent while or do-while loop?

Practice for loop In each problem below state what is printed unless directed otherwise. 1. int j=0; for(int g=0; g< 5; g++) j++; System.out.println(j); int s=1; for(int j=3; j >+0; j--) { s = s+j; } System.out.println(s);

Nested for loop When one loop is placed inside another loop for(int j=0; j < 5; j++) { System.out.println(“outer loop”); for(int k = 0; k < 8; k++) { System.out.println(“inner loop”); } }

Flowchart It allows user to design the logical flow of a program without first getting into the details of specific code. Flowcharts use symbols and text to give a visual representation of a solution. indicates start or end. indicates input/ouput. indicates a decision indicates the process

The BirthdayGame flowchart Start birthDay = number %100 Display steps for calculating numbers Display player’s birthday Prompt user for number End Substract 165 from numbers birthMonth = number/100

Example of decision symbol yes no If (input number==secrete number)? Display “sorry, better luck next time” Display “you guess it”

Debugging Technique Debugging is the process of getting an application to work correctly. Additional println Adding println() statements just after a variable is assigned a new value or before and after a condition is evaluated can help detect the source of a logic error. Variable trace A variable trace is a table listing the values of variables at the points of assignment Debugger breakpoint

Println debugging example int num1 =0; int num2 = 0; while (num1 < 10) { if (num1 % 3 == 0) num2 = num2 + num1; System.out.println(num2 + “ “ ); } num1++

Variable trace num1 Num2 output 1 2 3 4 5 6 7 8 9

Practice for homework * ** *** **** ***** ****** ******* If we wanne print out the picture on the left, using the for loop?

Homework I. Draw a flowchart on the program gradeSystemConversion II. Using a for loop to print out a star triangle upside down like the following: ****** ***** **** *** ** *