• 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

a question for "For loop".

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
please look at the question below

which one is the correct answer and what about the rest of the choices?
Thanks

Sura
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usually Mock Exams have their answers provided. Where exactly does this question come from?

What happens when you compile each of these expressions?
[ October 18, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sura,

Acording to me only a and d are the coorect answers.

arnab
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello arnab,
i think u have made wrong decision in ur choices.
according to me,

choice a) is wrong because identifier 'j' is declared and initialized in "for" loop after declaring same variable 'j' inside the method before "for" loop.

choice b) is wrong because comparision part of "for" loop doesn't evaluate to a boolean value.

choice c) is correct because it follows all the rules.

choice d) is wrong because variable i is used without initializing it.

choice e) is wrong because the format of "for" loop declaration is only wrong
[ October 18, 2004: Message edited by: Anand B ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic