Thursday, 6 December 2012

Using Increment and Decrement Operators

              The increment operator (++) provides a shortcut to increase the value of a variable by one.The decrement operator (--) simply subtracts a value of one from a variable.The increment and decrement operators are helpful when used with loop counter variables.

<html>
<head>
<title>Increment and Decrement Operator</title>
</head>
<body>
<h3>Using Increment Operator</h3>
<%
int i=4;
%>
<p>
The value of <b>i</b> is <%=i%>
<br>
The value of <b>++i</b> is <%=++i %>
<p>
<h3>Using Decrement Operator</h3>
<p>
The value of <b>i</b> is <%=i %>
<br>
The value of <b>--i</b> is <%=--i%>
</body>
</html>

Description:

  • Assign an initial integer value to a variable.This variable will be used to illustrate the increment and decrement operators.
  • Type the increment operator (++) before the variable name and use the Expression tag to print the result to the Web page.The variable will be incremented by one before it is displayed.
  • Type the decrement operator (--) before the variable name and use the Expression tag to print the result to the Web page.The variable will be decreased by one before it is displayed.

*******************************OUTPUT****************************************

Using Increment Operator

The value of i is 4
The value of ++i is 5

Using Decrement Operator

The value of i is 5
The value of --i is 4


******************************************************************************

















No comments:

Post a Comment