Amazon.com Widgets Looping problems (mine)
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 20, 2013, 01:49:16 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 5 - Program Looping
| | | |-+  Looping problems (mine)
Pages: [1]   Go Down
Print
Author Topic: Looping problems (mine)  (Read 872 times)
anmldr
Jr. Member
**
Posts: 53






« on: October 14, 2009, 02:03:10 PM »

Please debug this for me.  I get 201 as the answer.

Code: (Objective-C)
	int n, triangularNumber;

triangularNumber = 0;

for (n=1; n<=200;++n);
triangularNumber +=n;

NSLog(@"The 200th triangular number is %i", triangularNumber);

Thanks,
Linda
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #1 on: October 14, 2009, 02:15:50 PM »

Linda,

Get rid of that ; at the end of the first line of the for.  That ends the loop right there!

Cheers,

Steve Kochan
Logged
anmldr
Jr. Member
**
Posts: 53






« Reply #2 on: October 14, 2009, 02:20:29 PM »

Thanks.  I was reviewing some of the starting webcasts again.

It is often a colon or a semi-colon that is the problem.

Linda
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.