• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using a while loop?

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic