Class Notes (807,071)
Canada (492,584)
ITM 200 (22)
Vikirmin (5)

Chapter 6 itm 200.docx

3 Pages
Unlock Document

Ryerson University
Information Technology Management
ITM 200

Chapter 6 While Loops whiLe () while: is a reserved word which tells the compilier that this a while loop statement Logic of while loops: 1) is evaluated 2) If has the value false, then is not executed 3) If has the value true, then is executed 4) is then evaluated again, and if it still true then is executed again 5) Loops until evaluates false Counter Controlled Loops Counter variables determine how many times the loops should be executed -the counter should be initalised (given a starting value) before the loop is entered Example: int counter=1; Example: counter= ; while(counter<= ) { counter=counter + ; } Increment Operator var++ Shorthands -= *= /= %= Example of +=: total += counter is total=total+counter Example: Print the sum of the numbers from 0 to n, where n is input by the user int counter=0; int total=0; String input; input=JOptionPane.showInputDialog("Enter a value for n:"); int n=Integer.parseInt(input)whilte (counter <=n) { total+= counter; counter __; } JOptionPane.showMessageDialog(null,"Sum to" + n +"is"+total); Example: Print a line of n starts in the command window String input; Input= JOptionPane.showInputDialog(“How many stars?”); Int n=Integer.parse.Int(input); Int counter=1; While (counter<=n) { System.out.print(“*”); Counter++; } Sentinel Controlled Loops -this form is used when we want the program to input a series of data items but the number of items is not known in advanced. On each repetition of the loop, a value if input. The repetition stops when a particular value in input which we must test for the loop test. Sentinel Value=a data item that is used to indicate the end of the input Example: While (valueInput != sentinelValu
More Less

Related notes for ITM 200

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.