• 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

Need help with a simple for loop

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I must make a 'for loop' to ask for a name, print it, ask again, print on next line ...... up to 20.
The code below works on the first one and never goes to the second.
HELP

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your loop termination expression is who1<=20, yet you are assigning whatever the user enters as a first name into the who1 variable.

So, what does it mean for a first name to be less than 20? Doesn't make much sense does it?

Are you actually trying to loop 20 times?
 
Kathryn McMahon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new at all of this.
Sorry about the tags.

My assignment is to have someone enter in 20 names and then stop the loop.

Thank you
Kathryn
 
Kathryn McMahon
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer your other question:
Yes, I am trying to loop 20 times.

Thank you again.
Kathryn
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so if you need to count from 0 to 19 (a total of twenty loops), why would you compare against the first name? What the value of the name winds up being has nothing at all to do with counting. Right?

You'd use a counter that would be independent from the first name.

To get you started, here's a loop that would count from 0 to 5; use it to write your own version:
reply
    Bookmark Topic Watch Topic
  • New Topic