• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt in loop  RSS feed

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to do a small process like this:a message will be played like this:"press 1 for analog,press 2 for digital,press 3 to go to previous menu". if i press 1 ,i have to print "analog".if 2 "digital".if 3 ,i have to go to previous menu which plays that message again.Now i did upto pressing 2.but when pressing 3,i dont know how to make it to go back to the same message.i need to put it in any for loop?
please assist me.my code follows:
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Preethi,

You can use do...while(); loop.
Rather then giving option like 'Go to previous menu' , you can do like this.
Options:
1) Do X thing.
2) Do Y thing.
...
10) Exit.

As it is in the loop it will automatically display the same list of options again.

What do you say?
[ June 14, 2008: Message edited by: Vishal Pandya ]
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couldn't i do it in for loop?
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by preethi Ayyappan:
couldn't i do it in for loop?

Yes, you can.
Did you try it in do...while(); loop. If you have tried then you could have easily done it in for loop too.

But, WHY do you want it into for loop only? I feel for this kind of scenarios do...while(); loop fits better.

Could you please elaborate your situation?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a for-loop is generally used when you know, in advance, exactly how many times you need to loop. in your case, since you don't (and really, can't) know in advance, a for-loop does not seem like the best choice.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.But i have done that using for loop like this.
.
Now what is happening is first i dial a number,it says welcome and ask us to press 0 for complaints.if i press 0 a voice file will tell us to press 1 for analog,2 for digital,3 for previous menu.before this i need to do like this.after saying welcome i need to play a message ("press 1 for english,press 2 for hindi").this should be played 3 times until the condition is satisfied.if the condition is satisfied, the message "for complaints press 0,or else hold the line" should be played.please help me to do this.

Thanks.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Preethi,

I concluded below points from your requirements.

1) Welcome message will be played.
2) "Press 1 for English and 2 for Hindi" This message will be played 3-times.
3) "Press 0 for complaints or hold the line". This is Main menu and it should be in loop.

Still i feel this can be achieved through do...while(); loop.

I have modified your code using do...while(); loop.




- "9 to end the call." I have added this condition to exit from the loop.Why do you want to execute the loop(for loop) only 3 times. Here you never know in advance that how many times the loop will be executed.

Is this properly interpreted?
[ June 16, 2008: Message edited by: Vishal Pandya ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!