Debian Codegraph @

help/info/if.html

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