• Post Reply Bookmark Topic Watch Topic
  • New Topic

if else statement inside a for loop  RSS feed

 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every body

can any body explain me what is the syntax for using if else statement inside a for loop.

i am trying but getting error.

can any body suggest me the answer.



an early reply would be appreciated.

here PresizeConstants is a class from where i am accessing UserStatusList which is an array of strings which has only two values
active and disabled

but due to current loop syntax which i am using , i am getting 4 values in the option select list. these two values are being are being displayed twice in the option list.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rammie you are using scriptlets in your code which is discouraged. This is not a good practice

rammie singh wrote:i am trying but getting error.

rammie singh wrote:i am getting 4 values in the option select list.


Are you getting an error or incorrect output. Looking at your code, I think it is mostly wrong.

 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ankit

well i will keeep this suggestion in my find from next time.

but since i have been using for loop many times in jsp..therefore i tried for if else inside the for loop.

any way what is the alternative for this.

and yes i am not getting the error ....the output is wrong.

if you could suggest me changes in this code it would be good for now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets went out over 6 years ago. You time would be best spent converting to JSTL/EL rather than debugging antiquated code.

That said, your syntax is all wrong. Your if keyword isn't even inside a scriptlet block. And do you really not indent your code?
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's true Bear Bibeault that use of scriplet inside jsp is discouraged.

Since i am new to this servlet and jsp and since i have already written it so for now i want this code to run. From next time i would keep this in mind.

but for now can you suggest me the changes for this code to run.

also i definately ident my code...it's just that while pasting the code in this forum they all came together.

Thanks.
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know it's a simple question but still can any body give me suggestion for changes to get the output.


here in option list my each values is getting repeated.


Thanks and Regards
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Wrong IF Condition check
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



so what is the alternative.


i have also used




can any body give me the solution
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rammie singh wrote:
so what is the alternative.
i have also used



probably you dont have a idea about <%= %>(Expression) . Why we use this ?
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks seetharaman venkatasamy

it was the same prob you mentioned. that is in for loop. it's running.

thanks.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rammie singh wrote:thanks seetharaman venkatasamy


You are welcome
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!