Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a while loop?

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By looking at the code below, could someone please tell me I can't use the value 'i' outside the while loop. I really need to! How do i go about this?
You shouldnt need to know what the code does, except for that I just want to use final value of 'i'.


[ February 07, 2006: Message edited by: Sam Bluesman ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm wondering about your logic (counter==numberOfActivities ?!) but i's scope allows you to use it after the while loop, since it was desclared before the while loop:
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but if i place a System.out.println(i) outside the while loop but still in the for loop nothing happens??
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Nothing happens" is different from a syntax error. It sounds like you have logical errors. Here's a demo that shows i can be used as I suggested.
 
Henry Wong
author
Marshal
Pie
Posts: 21510
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Bluesman:
but if i place a System.out.println(i) outside the while loop but still in the for loop nothing happens??


Two possible scenarios for this... either the for loop never executes or the while loop never finishes.

Put debugging messages before and after the for loop. Put debugging messages before and after the while loop. This should give you a hint as to what is going on...

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic