Loop Continue ISYS 350.

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
VB.Net Loops.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
VB.Net Loops. Loop FOR index – start TO end [STEP step] [statements] [EXIT FOR] NEXT index DO [{WHILE| UNTIL} condition] [statements] [EXIT DO] LOOP.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
Chapter 8 Using Repetition with Loops and Lists. Class 8: Loops and Lists Write Do loops to execute statements repeatedly Write For loops to execute statements.
JAVA Control Structures: Repetition. Objectives Be able to use a loop to implement a repetitive algorithm Practice, Practice, Practice... Reinforce the.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Programming Interface Controls ISYS 350. User Interface Controls Form MessageBox Common Controls: –Button, TextBox, MaskedTextBox, List Box, Option Button,
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Loops ISYS 350. A Box of Chocolate Repeat this process until box is empty: – Take one chocolate from the box – Eat the chocolate – Box has more chocolate?
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Programming Interface Controls ISYS 350. User Interface Controls Form MessageBox Common Controls: –Button, TextBox, MaskedTextBox, List Box, Option Button,
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Loop Continue ISYS 350. Straight Line Depreciation Table.
Loops ISYS 350. Two Types of Loops while loop for loop.
A: A: double “4” A: “34” 4.
Arrays. Array: Sequence of values of the same type Construct array: Store in variable of type double[ ] new double[10] double[] data = new double[10];
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
Loop Continue ISYS 350. Exiting a Loop Prematurely In some cases it is necessary to end a loop before the test condition would end it Use the break statement:
Loop Continue ISYS 350. Exiting a Loop Prematurely In some cases it is necessary to end a loop before the test condition would end it Use the break statement:
Loops ISYS 350. Two Types of Loops while loop for loop.
CSC 230 (Blum)1 Getting a List of Colors. CSC 230 (Blum)2 Imagine a program in which you want a list of colors in a ComboBox.
Introduction to Methods ISYS 350. Methods Methods can be used to break a complex program into small, manageable pieces – This approach is known as divide.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Loops ISYS 350. Two Types of Loops while loop for loop.
Programming Interface Controls ISYS 350. User Interface Controls Form MessageBox Common Controls: –Button, TextBox, MaskedTextBox, List Box, Option Button,
Programming Interface Controls ISYS 350. User Interface Controls Form MessageBox Common Controls: –Button, TextBox, MaskedTextBox, List Box, Option Button,
Array, ArrayList and List ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items.
CE En 270 Brigham Young University Norm Jones
CSC111 Quick Revision.
Array ISYS 350.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Loops ISYS 350.
Chapter 7: Working with Arrays
Two Dimensional Array Mr. Jacobs.
2. Java language basics (2)
Loops ISYS 350.
Incrementing ITP © Ron Poet Lecture 8.
IS 350 Loops.
Programming Interface Controls
Array ISYS 350.
Array ISYS 350.
Arrays … The Sequel Applications and Extensions
Review Operation Bingo
Array ISYS 350.
Loops ISYS 350.
Array ISYS 350.
Loop Continue ISYS 350.
Loops ISYS 350.
Loop Continue ISYS 350.
Introduction to Problem Solving and Control Statements
Loops ISYS 350.
Lecture Set 10 Windows Controls and Forms
Loops ISYS 350.
Loop Continue.
Loop Continue ISYS 350.
Loops ISYS 350.
Loop Continue ISYS 350.
Loops ISYS 350.
Array ISYS 350.
Loops ISYS 350.
Loop Continue ISYS 350.
Loop Continue ISYS 350.
Programming Interface Controls
Adding and Subtracting
Presentation transcript:

Loop Continue ISYS 350

Exiting a Loop Prematurely In some cases it is necessary to end a loop before the test condition would end it Use the break statement: break;

Years to Reach Targeted Future Value Future Value=Present Value Years to Reach Targeted Future Value Future Value=Present Value*(1+Rate)Year

Method 1 double PresentValue, Rate, Target, YearToTarget, futureValue; PresentValue = double.Parse(textBox1.Text); Rate = double.Parse(textBox2.Text); Target = double.Parse(textBox3.Text); futureValue = PresentValue; YearToTarget = 0; while (futureValue < Target) { YearToTarget = YearToTarget + 1; futureValue = PresentValue * Math.Pow(1 + Rate,YearToTarget); } textBox4.Text = YearToTarget.ToString();

Method 2 double PresentValue, Rate, Target, YearToTarget, futureValue; PresentValue = double.Parse(textBox1.Text); Rate = double.Parse(textBox2.Text); Target = double.Parse(textBox3.Text); YearToTarget = 0; while (true) { futureValue = PresentValue * Math.Pow(1 + Rate, YearToTarget); if (futureValue >= Target) break; YearToTarget = YearToTarget + 1; } textBox4.Text = YearToTarget.ToString();

Method 3 double PresentValue, Rate, Target, YearToTarget, futureValue; PresentValue = double.Parse(textBox1.Text); Rate = double.Parse(textBox2.Text); Target = double.Parse(textBox3.Text); for (YearToTarget = 0; YearToTarget<99999; YearToTarget++) { futureValue = PresentValue * Math.Pow(1 + Rate, YearToTarget); if (futureValue >= Target) break; } textBox4.Text = YearToTarget.ToString();

Searching: If fruit not exists, then add to the combobox

Code Example: Using Flag string testItem; testItem = comboBox1.Text; Boolean foundFlag=false; for (int counter = 0; counter <= comboBox1.Items.Count - 1; counter++) { if (testItem == comboBox1.Items[counter].ToString()) foundFlag = true; break; } if (foundFlag) MessageBox.Show("item already exist"); else MessageBox.Show("item added"); comboBox1.Items.Add(testItem);

Method 2: Using .Net’s Support string testItem; testItem = comboBox1.Text; if (comboBox1.Items.Contains(testItem)) MessageBox.Show("item already exist"); else { MessageBox.Show("item added"); comboBox1.Items.Add(testItem); }

Straight Line Depreciation Table

dataGridView Control Properties ColumnCount: specify the number of columns dataGridView1.ColumnCount = 4; Columns collection each column is identified by an index Each column has a HeaderText property: Ex. dataGridView1.Columns[0].HeaderText = "Year"; Rows collection Clear all rows: dataGridView1.Rows.Clear(); each row is identified by an index Adding a blank row: dataGridView1.Rows.Add(); Each Row has a Cells collection Each cell is identified by an index Has a value property: dataGridView1.Rows[year - 1].Cells[0].Value = year;

Depreciation Table Code Example dataGridView1.ColumnCount = 4; dataGridView1.Columns[0].HeaderText = "Year"; dataGridView1.Columns[1].HeaderText = "Value at Begining of Year"; dataGridView1.Columns[2].HeaderText = "Depreciation During Year"; dataGridView1.Columns[3].HeaderText = "Total depreciation to End of Year"; double value, life, depreciation, totalDepreciation=0; value = double.Parse(textBox1.Text); life = double.Parse(textBox2.Text); depreciation = value / life; dataGridView1.Rows.Clear(); for (int year = 1; year <= life; year++) { dataGridView1.Rows.Add(); dataGridView1.Rows[year - 1].Cells[0].Value = year; dataGridView1.Rows[year - 1].Cells[1].Value = value.ToString("c"); dataGridView1.Rows[year-1].Cells[2].Value = depreciation.ToString("c"); totalDepreciation += depreciation; dataGridView1.Rows[year - 1].Cells[3].Value = totalDepreciation.ToString("c"); value -= depreciation; }