<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2008 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>If</TITLE> <META NAME="description" CONTENT="If"> <META NAME="keywords" CONTENT="gnuplot"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2008"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="gnuplot.css"> <LINK REL="next" HREF="node109.html"> <LINK REL="previous" HREF="node107.html"> <LINK REL="up" HREF="node88.html"> <LINK REL="next" HREF="node109.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html2521" HREF="node109.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html2515" HREF="node88.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html2509" HREF="node107.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html2517" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html2519" HREF="node467.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html2522" HREF="node109.html">Iteration</A> <B> Up:</B> <A NAME="tex2html2516" HREF="node88.html">Commands</A> <B> Previous:</B> <A NAME="tex2html2510" HREF="node107.html">History</A> <B> <A NAME="tex2html2518" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html2520" HREF="node467.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H1><A NAME="SECTION04090000000000000000"></A> <A NAME="commands_if"></A><A NAME="if"></A><A NAME="2432"></A> <BR> If </H1> The <B>if</B> command allows commands to be executed conditionally. <P> Syntax: <BR> <PRE> if (<condition>) <command-line> [; else if (<condition>) ...; else ...] </PRE> <BR> <P> 4#4condition5#5 will be evaluated. If it is true (non-zero), then the command(s) of the 4#4command-line5#5 will be executed. If 4#4condition5#5 is false (zero), then the entire 4#4command-line5#5 is ignored until the next occurrence of <B>else</B>. Note that use of <B>;</B> to allow multiple commands on the same line will <EM>not</EM> end the conditionalized commands. <P> Examples: <BR> <PRE> pi=3 if (pi!=acos(-1)) print "?Fixing pi!"; pi=acos(-1); print pi </PRE> <BR> will display: <BR> <PRE> ?Fixing pi! 3.14159265358979 </PRE> <BR> but <BR> <PRE> if (1==2) print "Never see this"; print "Or this either" </PRE> <BR> will not display anything. <P> else: <BR> <PRE> v=0 v=v+1; if (v%2) print "2" ; else if (v%3) print "3"; else print "fred" </PRE> <BR> (repeat the last line repeatedly!) <P> See <B>reread (p. <A HREF="node172.html#reread"><IMG ALIGN="BOTTOM" BORDER="1" ALT="[*]" SRC="crossref.png"></A>)<A NAME="2448"></A></B> for an example of how <B>if (p. <A HREF="node108.html#if"><IMG ALIGN="BOTTOM" BORDER="1" ALT="[*]" SRC="crossref.png"></A>)<A NAME="2450"></A></B> and <B>reread (p. <A HREF="node172.html#reread"><IMG ALIGN="BOTTOM" BORDER="1" ALT="[*]" SRC="crossref.png"></A>)<A NAME="2452"></A></B> can be used together to perform a loop. <BR><HR> <ADDRESS> 2010-08-17 </ADDRESS> </BODY> </HTML>