Premium Essay

Prg 420 Week 3 Supporting Activity 1

In:

Submitted By peacebear241
Words 273
Pages 2
There are 3 kinds of loops—for loop, while loop, and do while loop. Under which circumstances would each kind of loop be more appropriate? Explain your answers using specific examples.

For loop- The for loop is best used when the number of iterations is known. The for loop is best used to repeat the loop a fixed number of times. The Boolean-expression is tested at the beginning of the loop. The for loop has the form: for (initialization; Boolean-expression; increment) {nested statements }.
A for loop can be used to show every number divisible by 3 between 1 and 60.
For (int num=0; num , 60; num++) { If (num % 3 == 0) { System.out.println( “#: “ + dex);
}
}
While loop- While loops are best used when the exiting condition has nothing to do with the number of loops. The While loop tests the Boolean-expression at the beginning of the loop. It is in the form :
While (Boolean-expression) { nested statements}
The while loop can be used to prompt the user until the exit variable (any negative number) is entered. while ( input > 0) {
System.out.println(“Please enter number. Enter negative number to exit.”) }
Do while loop- It is best to use the do while loop when the iteration must be executed at least once. The do while loop tests the Boolean-expression at the end of the loop. It has the form: do { nested statements } while (Boolean-expression);
The do while loop can be used to show the same message multiple times. int tries = 3; int count = 1; do { System.out.println( “Incorrect password. Try again”); Count++;
} while (count <

Similar Documents

Premium Essay

Database Management System

...Copyeditor: Andrea Schein Proofreader: Foxxe Editorial Indexer: Elizabeth Cunningham Composition: GEX Publishing Services © 2011 Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at www.cengage.com/permissions Further permissions...

Words: 189848 - Pages: 760

Premium Essay

Sanitation in Ghana

...REPUBLIC OF GHANA THE BUDGET STATEMENT AND ECONOMIC POLICY of the GOVERNMENT OF GHANA for the 2015 FINANCIAL YEAR presented to PARLIAMENT on WEDNESDAY, 19TH NOVEMBER 2014 by SETH E. TERKPER Minister for Finance on the Authority of HIS EXCELLENCY PRESIDENT JOHN DRAMANI MAHAMA Theme: “Transformational Agenda: Securing the Bright Medium Term Prospects of the Economy ’’ THE 2015 BUDGET STATEMENT AND ECONOMIC POLICY ~ ii ~ Theme: “Transformational Agenda: Securing the Bright Medium Term Prospects of the Economy ’’ For copies of the Statement, please contact the Public Relations Office of the Ministry: Ministry of Finance Public Relations Office New Building, Ground Floor, Room 001/003 P. O. Box MB 40 Accra – Ghana The 2015 Budget Statement and Economic Policy of the Government of Ghana is also available on the internet at: www.mofep.gov.gh ~ iii ~ Theme: “Transformational Agenda: Securing the Bright Medium Term Prospects of the Economy ’’ ACRONYMS AND ABBREVIATIONS ABFA ACLP ADR AFCON AfDB AIDS AML AMSECs APR ATMA AVIC BACs BDS BIEPC BoG BOP bopd bps BR BRICS BSPs BVDs Annual Budget Funding Amount Ascertainment and Codification of Customary Law Project Alternative Dispute Resolution African Cup of Nations African Development Bank Acquired Immune Deficiency Syndrome Anti-Money laundering Agricultural Mechanization Services Enterprise Centres Annual Progress Report Accra-Tema Metropolitan Area Accra Visitor Information Centre Business Advisory Centres...

Words: 63016 - Pages: 253

Free Essay

Avon in Global Market in 2009, Managing and Developing a Global Workforce

...The London School of Economics and Political Science THE ROLE OF CIVIL SOCIETY IN THE DEMOCRATISATION OF GLOBAL GOVERNANCE INSTITUTIONS: From ‘Soft Power’ to Collective Decision-Making? Saif Al-Islam Alqadhafi A thesis submitted to the Department of Philosophy of the London School of Economics for the degree of Doctor of Philosophy, London, September 2007 Declaration I certify that the thesis I have presented for examination for the MPhil/PhD degree of the London School of Economics and Political Science is solely my own work other than where I have clearly indicated that it is the work of others (in which case the extent of any work carried out jointly by me and any other person is clearly identified in it). The copyright of this thesis rests with the author. Quotation from it is permitted, provided that full acknowledgement is made. This thesis may not be reproduced without the prior written consent of the author. I warrant that this authorisation does not, to the best of my belief, infringe the rights of any third party. 2 Abstract This dissertation analyses the problem of how to create more just and democratic global governing institutions, exploring the approach of a more formal system of collective decision-making by the three main actors in global society: governments, civil society and the business sector. The thesis seeks to make a contribution by presenting for discussion an addition to the system of international governance that is morally...

Words: 127847 - Pages: 512

Premium Essay

Textbook

...This page intentionally left blank Introductory Econometrics for Finance SECOND EDITION This best-selling textbook addresses the need for an introduction to econometrics specifically written for finance students. It includes examples and case studies which finance students will recognise and relate to. This new edition builds on the successful data- and problem-driven approach of the first edition, giving students the skills to estimate and interpret models while developing an intuitive grasp of underlying theoretical concepts. Key features: ● Thoroughly revised and updated, including two new chapters on ● ● ● ● ● ● panel data and limited dependent variable models Problem-solving approach assumes no prior knowledge of econometrics emphasising intuition rather than formulae, giving students the skills and confidence to estimate and interpret models Detailed examples and case studies from finance show students how techniques are applied in real research Sample instructions and output from the popular computer package EViews enable students to implement models themselves and understand how to interpret results Gives advice on planning and executing a project in empirical finance, preparing students for using econometrics in practice Covers important modern topics such as time-series forecasting, volatility modelling, switching models and simulation methods Thoroughly class-tested in leading finance schools Chris Brooks is Professor of Finance at the ICMA Centre, University...

Words: 195008 - Pages: 781

Premium Essay

Econometrics

...This page intentionally left blank Introductory Econometrics for Finance SECOND EDITION This best-selling textbook addresses the need for an introduction to econometrics specifically written for finance students. It includes examples and case studies which finance students will recognise and relate to. This new edition builds on the successful data- and problem-driven approach of the first edition, giving students the skills to estimate and interpret models while developing an intuitive grasp of underlying theoretical concepts. Key features: ● Thoroughly revised and updated, including two new chapters on ● ● ● ● ● ● panel data and limited dependent variable models Problem-solving approach assumes no prior knowledge of econometrics emphasising intuition rather than formulae, giving students the skills and confidence to estimate and interpret models Detailed examples and case studies from finance show students how techniques are applied in real research Sample instructions and output from the popular computer package EViews enable students to implement models themselves and understand how to interpret results Gives advice on planning and executing a project in empirical finance, preparing students for using econometrics in practice Covers important modern topics such as time-series forecasting, volatility modelling, switching models and simulation methods Thoroughly class-tested in leading finance schools Chris Brooks is Professor of Finance...

Words: 195008 - Pages: 781