It's not a secret anymore!
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes mock exam question doubt from ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "mock exam question doubt from ?" Watch "mock exam question doubt from ?" New topic

mock exam question doubt from ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924

following is the question ;

Questions no -20

What get printed when the following JSTL code fragment is executed?

<%@ taglib uri="" prefix="c" %>
<c:set var="item" value="2"/>
<c:forEach var="item" begin="0" end="0" step="2">
<cut value="${item}" default="abc"/>


the correct answer is OPTION A i.e. 0. i thought the answer should be 2. i ran it but it is coming out to be 0. checked syntax for forEach tag and didnt find a thing. please help ?
Vijay Vishwa
Ranch Hand

Joined: Nov 21, 2010
Posts: 32
Let put it through similar simple java loop

This is what happening is the JSTL code also

item varable is declared and set to 2

Next in the for loop, the counter varaible is item and loop starts and ends with 0
So in the first iteration 0 is assigned to the item and that is what printed.

SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157

you have initialized your item variable again for looping, so has nothing to do with your previous assignment.
Atul Shrivastava

Joined: Jan 12, 2009
Posts: 19

you started with 0 and the loop ended on 0 itself, resulting in the output 0.

OCP (SCJP) - Java 1.6
I agree. Here's the link:
subject: mock exam question doubt from ?
It's not a secret anymore!