Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | <!-- |
2 | Copyright (c) 2000-2014 Ericsson Telecom AB | |
3 | ||
4 | All rights reserved. This program and the accompanying materials | |
5 | are made available under the terms of the Eclipse Public License v1.0 | |
6 | which accompanies this distribution, and is available at | |
7 | http://www.eclipse.org/legal/epl-v10.html | |
8 | --> | |
9 | <html> | |
10 | <head> | |
11 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
12 | <meta http-equiv="Content-Language" content="en-us"> | |
13 | <title>if</title> | |
14 | </head> | |
15 | <body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258"> | |
16 | <table align="left" border="0" cellspacing="0" cellpadding="0" valign=top> | |
17 | <tr> | |
18 | <td width=105 height=40><a href="https://projects.eclipse.org/projects/tools.titan"><img src="../images/titan_transparent.gif" border=0 width=105 height=40 align="left" alt="Titan"></a></td> | |
19 | </tr> | |
20 | </table> | |
21 | <table border="0" align="right" cellpadding="0" cellspacing="0"> | |
22 | <tr> | |
23 | <td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td> | |
24 | <td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td> | |
25 | <td><a href="hexstring.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> | |
26 | <td><a href="ifpresent.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td> | |
27 | </tr> | |
28 | </table> | |
29 | <p><br clear="all"> | |
30 | </p> | |
31 | <hr> | |
32 | <h1>if</h1> | |
33 | <blockquote> | |
34 | <p>1. <a href="#4.">Conditional statement with one alternative</a></p> | |
35 | <p>2. <a href="#5.">Conditional statement with two alternatives</a></p> | |
36 | <p>3. <a href="#5.">Conditional statement with several alternatives</a></p> | |
37 | </blockquote> | |
38 | <p>The conditional statement is used to branch in the program execution in function of Boolean expression. It is possible to chain more than one such branching in one program statement.</p> | |
39 | <p>Related keywords:</p> | |
40 | <ul> | |
41 | <li><a href="else.html"><b><font face="Courier New" color="#003258" size="4">else</font></b></a></li> | |
42 | </ul> | |
43 | <hr align="left" width="75%"> | |
44 | <h4><a name="4.">1. Conditional statement with one alternative</a></h4> | |
45 | <hr align="left" width="50%"> | |
46 | <div align="center"> | |
47 | <center> | |
48 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
49 | <tr> | |
50 | <td width="100%"> | |
51 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>if(</b></font><i> condition </i><font face="Courier New" color="#003258" size="5"><b>){</b></font> <i> | |
52 | statement_block </i><font face="Courier New" color="#003258" size="5"><b>};</b></font></h3> | |
53 | </td> | |
54 | </tr> | |
55 | </table> | |
56 | </center> | |
57 | </div> | |
58 | <ul> | |
59 | <li> | |
60 | <p>The <font face="Courier New" color="#003258" size="4"><b>if</b></font> keyword introduces the conditional statement.</p> | |
61 | </li> | |
62 | <li> | |
63 | <p><i>condition</i> is a Boolean expression.</p> | |
64 | </li> | |
65 | <li> | |
66 | <p><i>statement_block</i> contains one or more statements. The block will only be executed if the value of the preceding logical expression (<i>condition</i>) is true.</p> | |
67 | </li> | |
68 | </ul> | |
69 | <p><a href="#Ex4">Example</a></p> | |
70 | <hr align="left" width="75%" color="#0094D2"> | |
71 | <h4><a name="5.">2. Conditional statement with two alternatives</a></h4> | |
72 | <hr align="left" width="50%" color="#0094D2"> | |
73 | <div align="center"> | |
74 | <center> | |
75 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
76 | <tr> | |
77 | <td width="100%"> | |
78 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>if(</b></font><i> condition </i><font face="Courier New" color="#003258" size="5"><b>){</b></font> <i> | |
79 | statement_block<sub>1</sub> </i><font face="Courier New" color="#003258" size="5"><b>} else {</b></font> <i> statement_block<sub>2</sub> </i><font face="Courier New" color="#003258" size="5"><b>};</b></font> | |
80 | </h3> | |
81 | </td> | |
82 | </tr> | |
83 | </table> | |
84 | </center> | |
85 | </div> | |
86 | <ul> | |
87 | <li> | |
88 | <p>The <font face="Courier New" color="#003258" size="4"><b>if</b></font> keyword introduces the conditional statement .</p> | |
89 | </li> | |
90 | <li> | |
91 | <p><i>condition</i> is a Boolean expression.</p> | |
92 | </li> | |
93 | <li> | |
94 | <p>The <font face="Courier New" color="#003258" size="4"><b>else</b></font> keyword precedes the statement block to be executed when the <i>condition</i> is false.</p> | |
95 | </li> | |
96 | <li> | |
97 | <p><i>statement_block<sub>1</sub></i> contains one or more statements. The block will only be executed if the value of the preceding logical expression (<i>condition</i>) is true.</p> | |
98 | </li> | |
99 | <li> | |
100 | <p><i>statement_block<sub>2</sub></i> contains one or more statements. The block will only be executed if the value of the preceding logical expression (<i>condition</i>) is false.</p> | |
101 | </li> | |
102 | </ul> | |
103 | <p><a href="#Ex5">Example</a></p> | |
104 | <hr align="left" width="75%" color="#0094D2"> | |
105 | <h4><a name="5.">3. Conditional statement with several alternatives</a></h4> | |
106 | <hr align="left" width="50%" color="#0094D2"> | |
107 | <div align="center"> | |
108 | <center> | |
109 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
110 | <tr> | |
111 | <td width="100%"> | |
112 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>if(</b></font><i> condition<sub>1</sub> </i><font face="Courier New" color="#003258" size="5"><b>){</b></font> <i> | |
113 | statement_block<sub>1</sub> </i><font face="Courier New" color="#003258" size="5"><b>} else if(</b></font><i> condition<sub>n</sub> </i><font face="Courier New" color="#003258" size="5"><b>){</b></font> <i> | |
114 | statement_block<sub>n</sub> </i><font face="Courier New" color="#003258" size="5"><b>} else {</b></font> <i> statement_block<sub>x</sub> </i><font face="Courier New" color="#003258" size="5"><b>};</b></font> | |
115 | </h3> | |
116 | </td> | |
117 | </tr> | |
118 | </table> | |
119 | </center> | |
120 | </div> | |
121 | <ul> | |
122 | <li> | |
123 | <p>The <font face="Courier New" color="#003258" size="4"><b>if</b></font> keyword introduces the conditional statement.</p> | |
124 | </li> | |
125 | <li> | |
126 | <p><i>condition<sub>1</sub></i> is a Boolean expression.</p> | |
127 | </li> | |
128 | <li> | |
129 | <p><i>statement_block<sub>1</sub></i> contains one or more statements. The block will only be executed if the value of <i>condition<sub>1</sub></i> is true.</p> | |
130 | </li> | |
131 | <li> | |
132 | <p>The <font face="Courier New" color="#003258" size="4"><b>else if</b></font> keyword pair precedes the next condition (<i>condition<sub>n</sub></i>) to be checked. The keyword pair and | |
133 | the following <i>condition<sub>n</sub></i> and <i>statement_block<sub>n</sub></i> may be repeated as many times as needed.</p> | |
134 | </li> | |
135 | <li> | |
136 | <p><i>condition<sub>n</sub></i> is a Boolean expression.</p> | |
137 | </li> | |
138 | <li> | |
139 | <p><i>statement_block<sub>n</sub></i> contains one or more statements. The block will only be executed if the value of <i>condition<sub>n</sub></i> is true AND all preceding conditions (<i>condition<sub>i</sub></i>, | |
140 | where i = 1 .. n-1) are false.</p> | |
141 | </li> | |
142 | <li> | |
143 | <p>The <font face="Courier New" color="#003258" size="4"><b>else</b></font> keyword introduces the conditional statement.</p> | |
144 | </li> | |
145 | <li> | |
146 | <p><i>statement_block<sub>x</sub></i> contains one or more statements. The block will only be executed if the value of all preceding conditions (<i>condition<sub>i</sub></i>, where i = 1 .. | |
147 | n) is false.</p> | |
148 | </li> | |
149 | </ul> | |
150 | <p><a href="#Ex3">Example</a></p> | |
151 | <hr align="left" width="50%"> | |
152 | <p><a name="Ex4">Example 1</a>: | |
153 | <p><font face="Courier New">if (v_date == "1.1.2000") { log ( "apage" ) };</font></p> | |
154 | <p>When the variable v_date equals the character string 1.1.2000, the word apage will be written to the log.</p> | |
155 | <p><a name="Ex5">Example 2</a>: | |
156 | <p><font face="Courier New">if (v_datum == "1.1.2000") { log ( "apage" ) } else { log ( "satanas" ) };</font></p> | |
157 | <p>When the variable v_datum equals the character string 1.1.2000, the word apage, else the word satanas will be written to the log.</p> | |
158 | <p><a name="Ex3">Example 3</a>: | |
159 | <p><font face="Courier New">if (v_data == "red") { log ( "rot" ) } else if (v_data == "blue"){ log ( "blau" ) } else { log ( "duester" ) | |
160 | };</font></p> | |
161 | <p>When the variable v_data equals the character string red, the word rot will be written to the log. .When the variable v_data equals the character string blue, the word blau will be written to | |
162 | the log. When the variable v_data contains something else, the word duester will be written to the log. </p> | |
163 | <hr align="left" width="25%"> | |
164 | <hr align="left" width="25%"> | |
165 | <p><a HREF="BNF.html#conditionalconstruct">BNF definition</a> of <font face="Courier New"> if</font></p> | |
166 | </body> | |
167 | </html> |