One key point you need to know that, you can end a scriptlet tag anywhere you want. For example,
<%
if(true){
%>
<p>This is in the if-block. </p>
<%
out.println("This is that's it.");
}
%>
As you can see the first tag <% %> was ended unexpectedly to write the message This is in the if-block. This is a html line executed only if the if-condition is met. Isn't this simple?
Now let us write a program.
index.jsp
<%!
int a=10;
%>
<%
if(a==10)
{
%>
<b>This is bold text, I'm seen only when a==10</b>
<%
}
else
{
%>
<b>I am not seen, because a is not 10!</b>
<%
}
%>
<br/>I am after if-else.
Next: Using declarations with example